in angular.json buildOptimizer not allowed to be set for "serve"
See original GitHub issueπ Bug report
Command (mark with an x)
- new
- build
- serve
- test
- e2e
- generate
- add
- update
- lint
- xi18n
- run
- config
- help
- version
- doc
Is this a regression?
No, I think it is simple oversight in angular.json schemaDescription
Cannot disable AOT for serve if buildOptimizer set to true. due to
buildOptimizer is illegal option in serve
π¬ Minimal Reproduction
Iβve created a custom configuration
...
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/frontend",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": [
"src/assets/favicon.ico",
"src/assets/svg",
"src/assets/i18n"
],
"styles": ["src/styles.scss"],
"stylePreprocessorOptions": {
"includePaths": ["src/app/shared/", "src/assets/"]
},
"scripts": []
},
"configurations": [
...
"demo": {
"fileReplacements": [
],
"baseHref": "./",
"optimization": true,
"outputHashing": "none",
"sourceMap": true,
"aot": true,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "5mb",
"maximumError": "10mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
}
..
but for serving I want to turn of AOT, which is
I could do
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "frontend:build",
"baseHref": "/app/"
},
"configurations": {
"production": {
"browserTarget": "frontend:build:production"
},
"demo": {
"browserTarget": "frontend:build:demo",
"optimization": false,
"aot": false,
"sourceMap": true
}
}
},
but that will fail, because the βbuildOptimizeβ is true, and is not allowed to be set in serve configuration
π₯ Exception or Error
$ ng serve --configuration=demo
Schema validation failed with the following errors:
Data path "" should NOT have additional properties(buildOptimizer).
π Your Environment
$ ng version
Angular CLI: 9.1.1
Node: 12.16.2
OS: win32 x64
Angular: 9.1.1
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.901.1
@angular-devkit/build-angular 0.901.1
@angular-devkit/build-optimizer 0.901.1
@angular-devkit/build-webpack 0.901.1
@angular-devkit/core 9.1.1
@angular-devkit/schematics 9.1.1
@angular/cdk 9.2.0
@angular/material 9.2.0
@ngtools/webpack 9.1.1
@schematics/angular 9.1.1
@schematics/update 0.901.1
rxjs 6.5.5
typescript 3.8.3
webpack 4.42.0
Anything else relevant?
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (2 by maintainers)
Top Results From Across the Web
An unhandled exception occurred: The 'buildOptimizer' option ...
Go into your angular.json file; In that file, follow the path projects -> architect -> build -> options; Change "buildOptimizer" to true andΒ ......
Read more >ng build - Angular
Option Description Value Type Default Value
ββaot Build using Ahead of Time compilation. boolean true
ββbaseβhref Base url for the application being built. string
ββdeleteβoutputβpath Delete...
Read more >Angular Build Optimizations - IntSights
When we started using Angular, we enabled all the recommended build optimizations without taking into account their possible negative impact. ToΒ ...
Read more >What's new in Angular CLI 12.0? - Ninja Squad
json . ng update will automatically remove these options from your configuration. As Zone.js v0.10 is no longer supported, ngΒ ...
Read more >@angular-devkit/build-optimizer | Yarn - Package Manager
This package has always been experimental and never hit 1.0.0, meaning it should not be used directly outside of Angular. Angular Build Optimizer....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @Heerschop, you donβt need to create configurations in serve to use build configurations in the dev-server builder.
You can use
dev-server (ng serve),browserTargetoption.The command is a bit more verbose, but you wonβt need to include extra configurations in
angular.json.@Heerschop, you should use the new-ish multiple configurations feature. These are applied from left to right and allow you to override options like this:
Here, you basically provide the default production flags in the production config, then for each environment you override the files, but if you want a debug mode, you just add an extra
debugwhich changes some of the flags, likebuildOptimizer.BUT, the application configuration that varies between environments like staging, UAT and production, should be outside of the application bundle. You should set the API endpoint when you deploy the application, not when you build it, see #17786