我将我的项目设置为两个语言环境构建,每个语言环境都位于各自的URL(通过configuration.<locale>.baseRef
)。尽管此设置使我的开发服务器无法使用,但它可以很好地用于构建项目(通过ng build
)。如果我尝试运行npm start
,则会出现以下错误:
An unhandled exception occurred: The development server only supports localizing a single locale per build
这使得我不得不从projects.<app-name>.architect.build.options.localize
选项中删除一个构建名称(开发服务器将从["en-US"]
处的设置开始,而不是["en-US", "es-ES"]
)
我知道它很冗长,但是我在下面包含了angular.json的全部内容。我不知道需要调整哪些部分以允许构建多个可分发目录,同时仍然允许使用简单的开发服务器
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"console": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"i18n": {
"sourceLocale": "en-US",
"locales": {
"es-ES": "src/assets/i18n/messages.es-ES.xlf"
}
},
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"localize": ["en-US" ,"es-ES"],
"customWebpackConfig": {
"path": "./extra-webpack.config.js",
"replaceDuplicatePlugins": true
},
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": [
"src/assets",
"src/favicon.ico"
],
"styles": [
"node_modules/c3/c3.min.css",
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"es-ES": {
"outputPath": "dist/es-ES/",
"i18nLocale": "es-ES",
"i18nFile": "src/assets/i18n/messages.es-ES.xlf",
"baseHref": "/es-ES/"
},
"en-US": {
"outputPath": "dist/en-US/",
"baseHref": "/en-US/"
},
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"builder": "@angular-builders/custom-webpack:dev-server",
"options": {
"customWebpackConfig": {
"path": "./extra-webpack.config.js",
"replaceDuplicatePlugins": true
},
"browserTarget": "console:build:en-US"
},
"configurations": {
"es-ES": {
"browserTarget": "console:build:es-ES"
},
"production": {
"browserTarget": "console:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "console:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"karmaConfig": "./karma.conf.js",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"scripts": [],
"styles": [
"src/styles.scss"
],
"assets": [
"src/assets",
"src/favicon.ico"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"console-e2e": {
"root": "e2e",
"sourceRoot": "e2e",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "./protractor.conf.js",
"devServerTarget": "console:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"e2e/tsconfig.e2e.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "console",
"schematics": {
"@schematics/angular:component": {
"prefix": "app",
"style": "scss"
},
"@schematics/angular:directive": {
"prefix": "app"
}
},
"cli": {
"analytics": "62782045-42a1-4d0f-b379-e9a856db628d"
}
}