我可以使用Angular CLI有条件地加载脚本吗?
在这个文件中,我想根据环境或变量加载一个脚本.所以在生产中我想在开发时加载脚本而不是.有没有办法做到这一点?怎么样?
角cli.json
... "styles": [ "../node_modules/bootstrap/dist/css/bootstrap.css", "../node_modules/font-awesome/css/font-awesome.min.css", ], "scripts": [ "../node_modules/jquery/dist/jquery.js", "../node_modules/ion-rangeslider/js/ion.rangeSlider.js", "../node_modules/web-animations-js/web-animations.min.js", <---- LOAD HERE ONE SCRIPT DEPENDING ON ENVIRONMENT OR VARIABLE ], "environments": { "source": "environments/environment.ts", "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } ...
Leo.. 5
虽然@yuzuri建议了一个非常eleegnat解决方案 - 它需要你编辑一个不是一个好主意的节点模块..
这是一个简单的解决方法:
您可以编辑package.json文件下的"脚本"部分以获得:
"start": "cp angular-cli-dev.json angular-cli.json && ng serve" "build": "cp angular-cli-prod.json angular-cli.json && ng build"
然后你应该将angular-cli.json文件重命名为angular-cli-dev.json和angular-cli-prod.json每个应该有不同的配置 - 在我的例子中,"脚本"部分中的不同脚本.
希望在等待官方解决方案时有所帮助
虽然@yuzuri建议了一个非常eleegnat解决方案 - 它需要你编辑一个不是一个好主意的节点模块..
这是一个简单的解决方法:
您可以编辑package.json文件下的"脚本"部分以获得:
"start": "cp angular-cli-dev.json angular-cli.json && ng serve" "build": "cp angular-cli-prod.json angular-cli.json && ng build"
然后你应该将angular-cli.json文件重命名为angular-cli-dev.json和angular-cli-prod.json每个应该有不同的配置 - 在我的例子中,"脚本"部分中的不同脚本.
希望在等待官方解决方案时有所帮助