javascript - How to transformmodify a js file during a release in Azure DevOps - Stack Overflow

ScenarioCurrent state: I have an Angular 5 project which is on Azure DevOps. I push to DevTest and Pr

Scenario/Current state: I have an Angular 5 project which is on Azure DevOps. I push to Dev/Test and Prod from same branch (master). I have environment.ts file set up for my build so when I build my project from master it picks up the BaseAPIURL's depending on which environment I am building in. My master branch always using the mand using run-script build --env=dev.

What I am trying to achieve: I want to have one Build and multiple "Release" plans for different environment. By default upon build all the angular code is converted to .js files in my "dist" folder. The environment variable is present in main.bundle.js. How can I transform/modify that file during a release ?

Scenario/Current state: I have an Angular 5 project which is on Azure DevOps. I push to Dev/Test and Prod from same branch (master). I have environment.ts file set up for my build so when I build my project from master it picks up the BaseAPIURL's depending on which environment I am building in. My master branch always using the mand using run-script build --env=dev.

What I am trying to achieve: I want to have one Build and multiple "Release" plans for different environment. By default upon build all the angular code is converted to .js files in my "dist" folder. The environment variable is present in main.bundle.js. How can I transform/modify that file during a release ?

Share Improve this question edited Jul 14, 2019 at 7:33 Shayki Abramczyk 42k17 gold badges109 silver badges131 bronze badges asked Jul 12, 2019 at 19:10 HereToLearn_HereToLearn_ 1,1805 gold badges26 silver badges49 bronze badges 4
  • I think that it's a bad idea to modify any JS code after it was built. There is an option to use an APP_INITIALIZER factory which can get some config from wherever (I get it via http.get from json file in assets folder) where you can set all your environments and their corresponding settings. Then you just need to pick the one you need. – Sergey Commented Jul 12, 2019 at 19:13
  • 1 Can APP_INITIALIZER grab variables defined on DevOps Azure for the individual releases ? – HereToLearn_ Commented Jul 12, 2019 at 19:21
  • Not sure about that. Try to check it out. – Sergey Commented Jul 12, 2019 at 19:38
  • @HereToLearn_ Did you check my answer? – Shayki Abramczyk Commented Jul 22, 2019 at 4:45
Add a ment  | 

1 Answer 1

Reset to default 5

I agree with Sergey, is not remended to do it, but I did it in the past in an angular project.

It's simple, install Replace Tokens extension, in your environment.ts file put a placeholders for the values, for example:

baseUrl = __baseUrl__

In the release pipeline add a variable baseUrl for each environment with different value.

Now in each release environment (stage) add the replace tokens task and configure it to search the pattern __{variable}__:

So do it for all the variables (just add them in the variables tab and put the placeholders in the file).

If you want to use APP_INITIALIZER you can read this post that explain hot to do it with Azure DevOps.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745357884a4624224.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信