How to conditionally import different files during build in Angular 6?

前端 未结 1 1671
死守一世寂寞
死守一世寂寞 2021-01-20 00:30

Overview

I have Angular 6 app build by Angular CLI. Application is written in multiple languages. Each language has JSON file with translations of all the applicat

相关标签:
1条回答
  • 2021-01-20 00:35

    As part of the CLI 6.1 release, a feature was added that allows files to be replaced during the build other than .ts files. Previously this was used for the environment and environment.prod files

    Additional files can now be set with the fileReplacements key of the angular.json configurations. As far as I know, it should work with asset files, so .json should work. It's only been added recently, but there are issues/feature details that you can look up

    Let us know if it works out!

    P.S. If you don't want to complicate the angular.json configuration, you could create a .js node script, and run it before doing the build, passing in the language as a param, and replacing the relevant .json file in before building the Angular bundles

    0 讨论(0)
提交回复
热议问题