1

What is the difference, benefits, pros and cons of using following ways of including external scripts to Angular application (externalLib.js used in example):

  1. Include script reference directly into index.html file via script tag:
    <script src="../node_modules/jquery/dist/jquery.js"></script>

  2. Set path to library in angular-cli.json file in scripts array:
    "scripts": [ "../node_modules/path/to/lib/externalLib.js"]

  3. Include externalLib.js file in assets folder

In addition, does any of above methods support strong typing of library (i.e. automatic handling of externalLib.d.ts?

Thank you for help.

1
  • For your last question, the way you load an external js is not related to using that libraries typings. To load typings, you must install the libraries types ex. npm install @types/jquery --save-dev. If you look at your tsconfig.app.json it has "typeRoots": ["node_modules/@types"], this will tell the typescript compiler to use all your typings in that folder. Sidenote: often times when installing a typescript library, the types will be a dependency so you won't have to manually install, but since you are loading an external script, you most likely have to install the types manually Commented Oct 13, 2017 at 13:19

1 Answer 1

2
  1. Node module folder will not be in your output so path you refer to js file will not valid. So you need to change all this file path after each build.
  2. If you run build command then all file define in this section will bundle to one file in output.
  3. This will include your js file in asset folder in your build output so it will need to reference separately. No bundling for this type of files.
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.