在使用 Angular12 (版本 12.0.3)开发项目时,会出现调试运行正常,但是调用ng build 发布时出现报错信息。
提示:Index html generation failed. undefined:6:720366 missing '}'
或者:Index html generation failed. undefined:6:720366 missing ':' 等。
解决的方法是修改 angular.json 配置文件,在 build -> configurations -> production 节点下添加 optimization 节点:
"optimization": {
"scripts": true,
"fonts": {
"inline": true
},
"styles": {
"minify": true,
"inlineCritical": false
}
}
完整的节点路径为:
{
...,
"projects":{
"myapp":{
...,
"architect":{
...,
"build":{
...,
"configurations":{
...,
"production": {
...,
"optimization": {
"scripts": true,
"fonts": {
"inline": true
},
"styles": {
"minify": true,
"inlineCritical": false
}
}
}
},
...
},
...
},
...
}
},
...
}