如何使用angular-cli 4构建一次并部署多个环境? [英] How to build once and deployed multiple environments using angular-cli 4?

查看:100
本文介绍了如何使用angular-cli 4构建一次并部署多个环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们计划将angular部署到Amazon S3静态网站中,目前我们针对每种环境(开发/生产)进行单独的构建.是一种可以一次构建并部署到所有环境的解决方案.

We planned to deploy angular into amazon S3 static website, currently we are doing separate build for each environments(development/production). Is any solution to build once and deployed to all environment.

谢谢.

推荐答案

据我所知,您希望为多个堆栈(开发,测试,生产等)建立一个构建(例如,连续集成构建).如果您的环境文件中每个堆栈的设置都不同,则您将拥有不同的内部版本.您只有一个选择,只需一个构建即可实现这一目标.

As I understand you right you want to have one build (e.g. a continuous integration build) for several stacks (develop, test, production and so on). If you have different settings in your environment file for each stack you will have different builds. You have only one option to achieve that with only one build.

在您的开发环境文件中,保留您在本地进行开发所需的开发设置.在生产环境文件中,将占位符用于设置,这与开发设置不同.

In your develop environment file keep your developing settings, which you need for developing locally. In your production environment file use Placeholders for the settings, which are different to your developing settings.

然后,您始终可以构建用于生产的应用程序,并且您的应用程序将带有在main.*.bundle.js内部编译的占位符.

Then you can always build your application for production and you will have your application with the Placeholders compiled inside the main.*.bundle.js.

对于部署,您必须操作main.*.bundle.js文件(有占位符):

For Deployment you have to manipulate the main.*.bundle.js file (there are the Placeholders):

  1. 预部署:运行一个脚本,该脚本操纵main.*.bundle.js来设置例如生产设置.
  2. 部署:将应用程序部署到您的App Service
  3. 部署后:运行一个脚本,该脚本操纵main.*.bundle.js以再次设置占位符

是的,这不是一个很好的解决方案,但是经过3天的研究,这是最好的选择.然后,您可以通过运行脚本将应用程序部署到多个堆栈中.

Yes that isn't a nice solution, but after 3 days of researching this is the best option. You can then deploy your application for several stacks with running the scripts.

我使用Visuals Studio Team Services上的powershell脚本来执行此操作,以使用那里的发布功能将应用程序部署到Microsoft Azure.

I did this with powershell scripts on Visuals Studio Team Services to use the release functionality there to deploy the application to Microsoft Azure.

这篇关于如何使用angular-cli 4构建一次并部署多个环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆