Improve ng build --localize argument to accept locales instead of a boolean
🚀 feature request
Relevant Package
This feature request is for @angular/cli and possibly @angular/compiler-cli @angular/compiler @angular/localize.
Description
The --localize argument for the ng build command currenty only accepts true or false which sets the locales from predefined configurations in the angular.json file.
Describe the solution you'd like
Allow to set one or multiple locales through ng build --localize=en ng build --localize=en,fr.
Describe alternatives you've considered
The alternatives I found are;
- predefining each locale (and locale combination !) as a different configuration.
- building every locale
I believe both these alternatives do not fully benefit from the merits of the new faster way of making multiple localized builds.
Transferring to CLI project...
This is already possible.
https://github.com/angular/angular-cli/blob/1f42e071b4ae3ddee8b2eee1d27e8b6ad41e0cb0/packages/angular_devkit/build_angular/src/browser/schema.json#L212
@alan-agius4 , I'm receiving the following error. Perhaps I've made a mistake?
root:/[omitted]/resources/script [13:20]> yarn ng build --localize=fr
yarn run v1.22.5
$ /[omitted]/resources/script/node_modules/.bin/ng build --localize=fr
Cannot parse arguments. See below for the reasons.
Argument --localize could not be parsed using value "fr".Valid type(s) is: boolean
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
deps;
"dependencies": {
"@angular/animations": "^11.0.2",
"@angular/cdk": "^11.0.1",
"@angular/cli": "^11.0.2",
"@angular/common": "^11.0.2",
"@angular/compiler": "^11.0.2",
"@angular/core": "^11.0.2",
"@angular/forms": "^11.0.2",
"@angular/localize": "^11.0.2",
"@angular/material": "^11.0.1",
"@angular/material-moment-adapter": "^11.0.1",
"@angular/platform-browser": "^11.0.2",
"@angular/platform-browser-dynamic": "^11.0.2",
"@angular/router": "^11.0.2",
It looks like passing a non boolean is not working as expected when used via the CLI, but it does work when set in angular.json.
As a workaround you can use something like;
"configurations": {
"fr-de": {
"localize": ["fr", "de"]
},
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
Which you can then execute using ng build --configuration=production fr-de
Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular CLI version.
If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.