Load library file in index


Using http://valor-software.com/ng2-charts/ I must add a script tag in my index for:
<script src="node_modules/chart.js/src/chart.js"></script>

However, because the scope of the app does not see node_modules, I have to do:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>

Which is awful.

Is there a way to add a JS file to the build?

  • No, using import does not work in this case as it is needed as a global variable (the library is built that way)

here is great tutorial about chartjs and ionic2

in short , install it and use it where ever you want

npm install chart.js --save

import { Chart } from ‘chart.js’;


That is nice, However, this is not the only external script I need, and I am using a directive for it, that requires it to be loaded globally. I will apply this solution to my charts, sure, but is there a way to globally load other scripts?