这通常发生在使用 Angular CLI 启动新项目时,因为在项目中缺少默认的开发配置文件。为了解决这个问题,您可以手动添加一个开发配置文件,例如 webpack.dev.js
或 angular.json
。
以下是添加 angular.json
配置文件的示例:
ng config --list
命令,检查项目是否有默认的开发配置。如果没有,该命令将返回空值。$ ng config --list
{
"project": {
"name": "my-project",
"ejected": false,
"architect": {
"build": {},
"test": {}
}
}
}
angular.json
的文件,并将以下代码添加到其中:{
"projects": {
"my-project": {
"architect": {
"serve": {
"options": {
"browserTarget": "my-project:build"
},
"configurations": {
"production": {
"browserTarget": "my-project:build:production"
}
}
},
"build": {
"options": {
"outputPath": "dist/my-project",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,