Angular 7 SyntaxError:预期表达式,得到'<在生产中,每当basehref从根目录更改时 [英] Angular 7 SyntaxError: expected expression, got '< in production when ever basehref change from root

查看:82
本文介绍了Angular 7 SyntaxError:预期表达式,得到'<在生产中,每当basehref从根目录更改时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我通过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:预期表达式,得到'&lt;在生产中,每当basehref从根目录更改时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆