问题描述
每当我通过ng build --prod --base-href /v2/
将basehref更改为"/v2/"(或"/"以外的任何其他值)时,都会出现以下错误:
Whenever I change basehref to "/v2/" (or any other value other than "/") via ng build --prod --base-href /v2/
I get the following error:
Angular 7 SyntaxError:预期的表达式,得到了'<'
Angular 7 SyntaxError: expected expression, got '<'
推荐答案
这是一个矫kill过正:
this is an overkill:
ng build --aot --prod
因为prod总是执行aot,所以不需要参数,请使用:
because prod always performs aot so that parameter is not needed, please use:
ng build --prod --base-href
来源: https://angular.io/guide/deployment
也< base href ="/v2">而不是<基本href ="/v2/">
Also < base href="/v2"> instead of < base href="/v2/">
然后确保没有丢失资产,我添加了一个文件夹src/app/v2/assets/images并更新了CSS以引用新路径和angular.json
Then to make sure the assets are not lost I added a folder src/app/v2/assets/images and updated the css to reference the new path and the angular.json
"assets": ["src/favicon.ico","src/v2/assets"]
这篇关于Angular 7 SyntaxError:预期表达式,得到'<在生产中,每当basehref从根目录更改时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!