如何指定delete-output-path参数?Angular构建不覆盖dist目录配置
解决Angular CLI构建不覆盖dist目录的配置方法
好问题!我之前在Node+Express集成Angular的项目里也遇到过这个需求,不想每次ng build都清空dist目录,给你详细说下配置方式:
1. 配置在Angular CLI的配置文件中
这个delete-output-path参数是可以配置在Angular的CLI配置文件里的,但注意Angular版本不同,配置文件的名称和位置略有区别:
Angular 6及更早版本(使用angular-cli.json)
找到项目根目录下的angular-cli.json,在defaults -> build节点下添加deleteOutputPath属性,设置为false即可:
{ "project": { "name": "your-project-name" }, "defaults": { "build": { "deleteOutputPath": false, // 其他已有的build配置项... } } }
Angular 6+版本(使用angular.json)
从Angular 6开始,配置文件改成了angular.json,需要在projects -> 你的项目名称 -> architect -> build -> options里添加该属性:
{ "projects": { "your-project-name": { "architect": { "build": { "options": { "deleteOutputPath": false, "outputPath": "dist", // 这里是你的输出目录,保持原有配置即可 // 其他build配置项... } } } } } }
2. 关于tsconfig.json的说明
tsconfig.json是用来配置TypeScript编译规则的文件,不支持配置delete-output-path这类Angular CLI构建相关的参数,所以这个需求没法通过tsconfig.json来实现。
额外补充
如果只是临时需要一次不覆盖dist目录,也可以直接用命令行参数:
ng build --delete-output-path=false
但配置到CLI配置文件里后,每次执行ng build都会默认遵循这个规则,不用每次手动加参数。
内容的提问来源于stack exchange,提问作者u936293
相关产品推荐
相关产品推荐

