简体   繁体   English

托管Angular 2应用程序

[英]Hosting Angular 2 app

I'm new to Angular 2 , I know host Angular 1.x on shared hosting like GoDaddy , but I don't have idea how publish Angular 2 application, for example I have this structure folder: 我是Angular 2新手,我知道像GoDaddy一样在共享主机上主持Angular 1.x ,但我不知道如何发布Angular 2应用程序,例如我有这个结构文件夹:

angular2-quickstart

--app
  app.component.ts
  main.ts

--node_modules

--typings

index.html
package.json
styles.css
systemjs.config.js
tsconfig.json
typings.json

What file i need to upload on ftp? 我需要在ftp上传什么文件?

I don't tried anything because I don't know how to proceed 我没有尝试任何东西,因为我不知道如何继续
Thanks in advance! 提前致谢!

If you don't have a backend, free hosting sites will usually look for an index.html to begin their job. 如果您没有后端,免费托管网站通常会寻找index.html来开始他们的工作。 Hence, your folder structure is correct but you will need to upload the js files instead of the ts files. 因此,您的文件夹结构是正确的,但您需要上传js文件而不是ts文件。

As a component based language, angular 2 includes some caveats in it's deployment process. 作为基于组件的语言,angular 2在其部署过程中包含一些警告。 First, the files used in development environment aren't necessarily shipped to production. 首先,开发环境中使用的文件不一定要发送到生产环境。 In short, you'll only need to upload .js, .html and .css files . 简而言之,您只需要上传.js,.html和.css文件。

Second is that even if your application works deploying only the files mention above, it's advisable to include the following process: 其次,即使您的应用程序只能部署上面提到的文件,建议包括以下过程:

Bundling: Compiling all the .js files into single files. 捆绑:将所有.js文件编译为单个文件。 For instance, vendor.js could include all third party libs and bundle.js would include all application .js files. 例如,vendor.js可以包含所有第三方库,而bundle.js可以包含所有应用程序.js文件。 (Bundles are import for performance reasons, but bear in mind that with the arrival of http 2, this process will be abandoned) (捆绑包是出于性能原因导入的,但请记住,随着http 2的到来,这个过程将被放弃)

Minification: it's a standard process in all web apps, but now you only minify bundled files. 缩小:它是所有Web应用程序中的标准流程,但现在您只需缩小捆绑文件。

Take a look in this article, as it give some examples of tools that can help you with deployment process. 请看一下本文,因为它提供了一些可以帮助您部署过程的工具示例。 http://www.ninjaducks.in/hacking/angular-setup/ http://www.ninjaducks.in/hacking/angular-setup/

I think that one popular workflow is to gulp-typescript your .ts files, and send the resulting .js files into a distribution folder. 我认为一个流行的工作流程是gulp-typescript你的.ts文件,并将生成的.js文件发送到分发文件夹。 The many .js files could also be "gulp-concatenated" (gulp-concat) into one file. 许多.js文件也可以“gulp-concatenated”(gulp-concat)到一个文件中。

Of course you'll need to be sending your html and css files as well. 当然你也需要发送你的html和css文件。

Since the Angular2 library relies heavily on what's in the node_modules folder as well, you would need to upload your package.json and npm install on the server side. 由于Angular2库在很大程度上依赖于node_modules文件夹中的内容,因此您需要在服务器端上传package.json和npm install。 You could try uploading the node_modules but the upload takes a lot of time. 您可以尝试上传node_modules,但上传需要花费大量时间。

You need to build angular2 project using tools like webpack or angular-cli - which also uses webpack post beta.14 release. 你需要使用像webpack或angular-cli这样的工具来构建angular2项目 - 这也是使用webpack post beta.14发布的。 Webpack will create a distribution directory - dist - which you can deploy to the server. Webpack将创建一个分发目录 - dist - 您可以将其部署到服务器。 Webpack bundles all the code into a single file which it puts inside the dist folder. Webpack将所有代码捆绑到一个放在dist文件夹中的文件中。 Here's a good resource to understand the code and deployment structure of angular2 app: https://github.com/mirkonasato/angular2-course-webpack-starter 这是了解angular2应用程序的代码和部署结构的一个很好的资源: https//github.com/mirkonasato/angular2-course-webpack-starter

Clone the above directory, run "npm install" to install all dependencies and run "npm run build" you will see the distribution folder - dist - which you can deploy. 克隆上面的目录,运行“npm install”来安装所有依赖项并运行“npm run build”你会看到你可以部署的分发文件夹 - dist。

Well, you can run ng build in your root application directory. 那么,您可以在根应用程序目录中运行ng build。 It will create a dist directory containing the app and files. 它将创建一个包含app和文件的dist目录。 You can put this directory into the page the webserver will look for the index.html 您可以将此目录放入Web服务器将查找index.html的页面中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM