简体   繁体   English

Angular 4生产部署工作流程

[英]Angular 4 Production Deployment Workflow

I have a lengthy discussion with a colleague about how we should deploy our angular 4 app to production server. 我和一位同事进行了很长的讨论,讨论如何将angular 4应用程序部署到生产服务器。

Would like practical advise and guide on this issue from the community, if possible. 如果可能,希望社区提供有关此问题的实用建议和指南。

Premise 1 前提1
At production server, 在生产服务器上,

git pull
npm install
{set up production configuration}
ng build --prod --aot
  • build and compile on production server 在生产服务器上构建和编译
  • production server hardware specs need to support the build process 生产服务器硬件规格需要支持构建过程
  • addition space required on hosting server to house node_modules 托管服务器上用于容纳node_modules的附加空间
  • git repo master branch does not have compiled codes, therefore is a "clean source repo" git repo master分支没有编译的代码,因此是“干净的源repo”

Premise 2 前提2
At production server, 在生产服务器上,

git pull
  • build and compile production codes on local development workstation will be faster 在本地开发工作站上构建和编译生产代码将更快
  • git repo master branch will keep snapshot of the compiled codes for deployment git repo master分支将保留已编译代码的快照以供部署
  • production server remains as a 128MB RAM with limited space, since it is to serve html, js and css. 生产服务器仍保留为有限空间的128MB RAM,因为它可用于html,js和css。
  • faster deployment to another server when required for recovery or scaling, since it is only a git pull 需要进行恢复或扩展时,可以更快地将其部署到另一台服务器,因为这只是git pull

The best way to do it, is to build and compile in the local development Workstation, and deploy only the output of the build. 最好的方法是在本地开发工作站中构建和编译,并仅部署构建的输出。

The git repo master branch needs to contain the source code not the only compiled&built one. git repo master分支需要包含源代码,而不是唯一编译和构建的源代码。

You can deploy in the production server using other method rather then the git pull command but if you insist on using it, you can init a new repo in the /build file and pull this repo to the production server. 您可以使用其他方法而不是git pull命令在生产服务器中进行部署,但是如果您坚持使用它,则可以在/ build文件中初始化一个新的存储库,然后将该存储库拉到生产服务器。

If you really can't afford the build farm yet and if it enables the testing or other activites, yeah sure. 如果您真的负担不起构建服务器场,并且可以启用测试或其他活动,那么可以。 Test the workflow you describe and see it for yourself, but it's definitely not a good long term practice. 测试您描述的工作流程并亲自查看,但这绝对不是一个好的长期实践。

If eventually you're gonna use the CI in your workflow, I would suggest to just start trying to set it up instead of wasting time/money setting up something temporary. 如果最终您将在工作流中使用CI,我建议您开始尝试进行设置,而不要浪费时间/金钱来临时设置。 Moreover, 5 minutes isn't a big deal trust me. 而且,5分钟对我来说并不重要。

As a side note: If you would have spent time trying your suggestion instead of writing your SO question and talking with your colleague, you probably would already have figured out the answer yourself. 附带说明:如果您将时间花在尝试您的建议上,而不是写下您的SO问题并与同事交谈,您可能已经自己想出了答案。

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

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