Angular cli includes / excludes scripts in index.html depending on the environment

I have an angular 2 application (angular cli). And I want to create a web and mobile (cord) version for the application.

Therefore, I want to use cordova ng build -e prodfor assembly for production and ng build -e cordova --output-path mobile/www --base-href ./for creating a project.

I want to include <script type="text/javascript" src="cordova.js"></script>if the environment is a corridor and exclude the api script website, and vice versa if the environment is production

+4
source share
1 answer

Found a solution.

Based on Jonaru's answer on this issue

In main.ts:

if (environment.production) {

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

  enableProdMode();
}

, , index.html

+2

Source: https://habr.com/ru/post/1664469/


All Articles