如何将Angular CLI 1.7.2的.angular-cli.json转换为6.x的angular.json格式?
嘿,我来帮你把Angular CLI 1.7.2的配置转换成6.x版本的angular.json格式,其实非常直观,核心就是调整配置项的结构,同时保留原有的路径即可:
转换后的完整配置片段
在你的angular.json文件中,找到对应项目的build配置下的options部分,替换成以下内容:
"styles": [ { "input": "../scss/bootstrap/bootstrap.scss" }, { "input": "../src/assets/styles/icon8.css" }, { "input": "styles.scss" }, { "input": "styles-props.css" } ], "scripts": [ { "input": "../node_modules/web-animations-js/web-animations.min.js" }, { "input": "../node_modules/jquery/dist/jquery.js" } ]
额外说明
- 格式灵活性:Angular 6+的
styles和scripts数组支持两种写法:- 上面用的是对象格式,适合后续需要添加
bundleName、lazy等高级配置的场景; - 如果不需要额外配置,也可以简化成更简洁的字符串数组形式:
"styles": [ "../scss/bootstrap/bootstrap.scss", "../src/assets/styles/icon8.css", "styles.scss", "styles-props.css" ], "scripts": [ "../node_modules/web-animations-js/web-animations.min.js", "../node_modules/jquery/dist/jquery.js" ]
- 上面用的是对象格式,适合后续需要添加
- 路径兼容性:你原有的相对路径不需要修改,因为angular.json和旧版的.angular-cli.json一样位于项目根目录,路径的相对指向逻辑完全一致。
内容的提问来源于stack exchange,提问作者st_clair_clarke
相关产品推荐
相关产品推荐

