![](/img/trans.png)
[英]How to change variable value in index.html based on the environment in angular
[英]angular cli include/exclude scripts in index.html depending on the environment
我有角度2應用(使用角度cli)。 我想為應用程序構建Web和移動(cordova)版本。
因此,我想使用ng build -e prod
構建生產和ng build -e cordova --output-path mobile/www --base-href ./
來構建cordova項目。
我想包括<script type="text/javascript" src="cordova.js"></script>
如果環境是cordova並排除facebook web api腳本,反之亦然環境生產
找到了解決方案。
根據Ionaru在本期中的回答
在main.ts中:
if (environment.production) {
document.write(
`
<script type="text/javascript">
// JS code here
</script>
`
);
enableProdMode();
}
我認為這是有條件地嵌入代碼的最簡單方法,因為曾經直接在index.html上完成
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.