index.html中的角度cli包含/排除脚本,具体取决于环境

Gle*_*leb 7 javascript cordova webpack angular-cli

我有angular 2应用程序(使用了cli cli)。我想为该应用程序构建Web和移动(cordova)版本。

所以我想ng build -e prod用于生产和ng build -e cordova --output-path mobile/www --base-href ./科尔多瓦项目。

<script type="text/javascript" src="cordova.js"></script>如果环境是Cordova,则要包含;如果环境是生产环境,则要排除Facebook Web API脚本,反之亦然

coi*_*iso 6

找到了解决方案。

基于答案由Ionaru 这个问题

在main.ts中:

if (environment.production) {

  document.write(
    `
      <script type="text/javascript">
         // JS code here
      </script>
    `
  );

  enableProdMode();
}
Run Code Online (Sandbox Code Playgroud)

我相信这是有条件地嵌入代码的最简单方法,因为直接在index.html上完成一次