给定的解决方案"resourcesOutputPath": "images"
适用于图像。但不幸的是,如果我们需要对其他资源(如文件*.js
或*.ttf
文件等)做同样的事情......它将无法正常工作。
这是我对*.js
文件执行此操作的方法:在文件中,在节点package.json
下方,我添加了一个名为的脚本,该脚本将:scripts
postbuild
- 移动专用文件夹中的文件(
resources
在我的示例中)
- 搜索并替换
<script src="*.js"></script>
为index.html
。<script src="resources/*.js"></script>
搜索和替换是使用sed
命令行完成的(请注意,sed
在 linux 或 MacOS 上与 commande lin 存在一些差异)。
这是我的package.json
文件的最终外观:
{
"name": "my-project",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build",
"postbuild": "mv ./dist/my-project/*.js ./dist/my-project/*.js.map ./dist/my-project/resources; sed -i -e 's/src=\"/src=\"resources\\//g' dist/my-project/index.html",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
}
}