要在Angular 7中使用生产配置运行但仍启用开发模式,可以按照以下步骤进行操作:
@angular-builders/custom-webpack
插件:npm install @angular-builders/custom-webpack --save-dev
webpack.config.js
的文件,并将以下代码复制到该文件中:const webpack = require('webpack');
module.exports = {
mode: 'development',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
]
};
angular.json
文件,找到architect.build.configurations
部分,并在其中添加一个名为development
的新配置,将fileReplacements
指向environment.ts
文件:"configurations": {
"development": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.ts"
}
]
},
...
}
package.json
文件,并在scripts
部分的build
命令中添加--configuration=development
选项:"scripts": {
"build": "ng build --configuration=development",
...
}
现在,当你运行npm run build
命令时,Angular将使用生产配置运行,但仍然启用开发模式。