我要导入 aframe
在 <head>
使用 angular.json
标记配置为一个单独的包。
内部 angular.json
我有从我的 node_modules 导入的脚本:
"scripts": [
"node_modules/aframe/dist/aframe-v1.0.0.min.js"
]
这是在 html 正文的底部捆绑和导入的。
<body>
<app-root></app-root>
...
<script src="scripts.js" ...>
</body>
这是不可取的,因为库特别要求我在
<head>
中导入。 .此外,我想将其作为单独的包导入:
"scripts": [
{ "input": "node_modules/aframe/dist/aframe-v1.0.0.min.js", "bundleName": "aframe-v1.0.0.min" }
]
最佳答案
您可以像这样将脚本引用添加到 angular.json 作为示例包括 jquery 库
"scripts": [
{
"input": "node_modules/jquery/dist/jquery.min.js",
"inject": false,
"bundleName": "jquery"
}
]
然后将注入(inject)设置为
false
不会将脚本注入(inject) index.htm,最后我们只是为 bundleName 设置一个名称,这样脚本就不会与其他脚本文件捆绑,而是独立文件,现在您可以将脚本标签添加到标题标签
更新 index.html 并在标题中包含脚本标记
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Portfolio</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script src="jquery.js"></script> <!-- 👈 -->
</head>
<body>
<app-root></app-root>
</body>
</html>
关于javascript - 如何将脚本包含在 angular.json 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59416254/