7

I have angular 2 application (angular cli is used). And I want to build web and mobile (cordova) version for the app.

So I want to use ng build -e prod to build for production and ng build -e cordova --output-path mobile/www --base-href ./ to build for cordova project.

I want to include <script type="text/javascript" src="cordova.js"></script> if environment is cordova and exclude facebook web api script, and vise versa if environment is production

2
  • What solution did you go with? Commented Mar 11, 2017 at 7:24
  • Does it have to be in it's own script tag? If not you can use require('path/to/file.js) based on env Commented Apr 8, 2017 at 13:50

1 Answer 1

6

Found a solution.

Based on the answer by Ionaru in this issue

In main.ts:

if (environment.production) {

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

  enableProdMode();
}

I believe this to be the simplest way to conditionally embed code as once was done directly on index.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.