0

在 angular.json 文件中,我们有“脚本”部分(项目 -> 架构师 -> 脚本) 在这个数组中,我尝试加载一些脚本。第一个脚本工作正常,但 https 脚本不行。当我直接在浏览器中打开链接时它们可用,当我将它们添加到 index.html 的末尾时它们也会加载<script src="https://...>,但不知何故它在脚本数组中不起作用:

"scripts": [
          "node_modules/@webcomponents/custom-elements/src/native-shim.js",
          "https://my-server.com/polyfills.js",
          "https://my-server.com/polyfill-webcomp-es5.js",
          "https://my-server.com/polyfill-webcomp.js",
          "https://my-server.com/scripts.js",
          "https://my-server.com/main.js"
        ]

更多信息:

问题是,当我将它们作为标签添加到 index.html 中时,我会收到一个错误,而我在脚本数组中添加本地文件时却没有。我不知道在 index.html 或 angular.json 中添加脚本之间有什么区别,也许是脚本加载的顺序?无论如何我不能在本地添加脚本,我必须在运行时从外部服务器加载它们(我只在本地添加它们以进行测试,但在生产模式下我需要从服务器加载它们)

当我在本地添加文件并将它们加载到脚本数组中时,它工作得很好:

"scripts": [
          "node_modules/@webcomponents/custom-elements/src/native-shim.js",
          "src/scripts.js",
          "src/polyfills.js",
          "src/polyfill-webcomp.js",
          "src/polyfill-webcomp-es5.js",
          "src/main.js",
        ]
4

0 回答 0