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

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

问题描述

我们计划将 angular 部署到亚马逊 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. 部署:将应用程序部署到您的应用服务
  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天全站免登陆