简体   繁体   English

Angular-CLI:如何从node_modules中引用.js <script>-Tag?

[英]Angular-CLI: How to refer to .js from node_modules in <script>-Tag?

For IE11-compatibility, I read here that one should add <script src="node_modules/core-js/client/shim.min.js"></script> to the index.html. 对于IE11兼容性,我在这里读到应该将<script src="node_modules/core-js/client/shim.min.js"></script>到index.html。

However, when loading index.html, I always get a 404 for this file. 但是,在加载index.html时,我总是得到这个文件的404。 I have tried many different paths, eg "/scripts/shim.min.js" and read this and this but had no success. 我已经尝试了许多不同的路径,如"/scripts/shim.min.js"这个这个 ,但没有成功。

In the angular-cli.json "scripts": -array, I added "../node_modules/core-js/client/shim.min.js" and core-js is defined as a dependency in package.json 在angular-cli.json "scripts": -array,我添加了"../node_modules/core-js/client/shim.min.js"被定义为package.json中的依赖项。

Versions used: angular-cli: 1.0.0-beta.21, node: 4.2.6 使用的版本:angular-cli:1.0.0-beta.21,节点:4.2.6

In 1.0.0-beta.18 , there is a file src/polyfills.ts which imports a subset of core-js content. 1.0.0-beta.18中 ,有一个文件src/polyfills.ts polyfills.ts ,用于导入core-js内容的子集。 These imports are said to be performed early on - before the app itself. 据说这些进口是在应用程序本身之前进行的。

Thus, you should experiment with adding the import of your dependency to this file. 因此,您应该尝试将依赖项的导入添加到此文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM