我是angular2的新手,到目前为止我知道有两种方法可以将外部css / js添加到app中。
直接在index.html
使用npm install <package-name>
我正在尝试使用NPM目前无法使用的外部js。因此,将在index.html
现在,这是一个两部分问题。
index.html
中添加外部链接是否会减少angular build --prod --aot
中的构建时间(无论如何它已超快)?答案 0 :(得分:1)
Just to recap what I already said in the comments.
Adding the JS file into the index.html
may reduce your build time, but it will exclude it from being watch by WebPack. WebPack is bundling you files and also removed dead code or sorts out duplicated dependencies. So there is a definite advantage of importing it as node package using the npm install
But sometimes this is just not possible. Then you need to add it to your index.html, but you won't have any advantage out of this.
If your package is not on npm but on GitHub then you can easily install it from GitHub. Here a small example using the jQuery repo:
npm install https://github.com/jquery/jquery/tarball/master --save
重要的是,您使用 tarball 而不是树。这将在您的应用程序中安装jQuery。