CustomWebpack with Devkit/CLI 8.2 causes build options to get overridden/ignored
See original GitHub issueUpdate: Related issue in Angular CLI repo: https://github.com/angular/angular-cli/issues/16098
Describe the bug
This is a hard bug to describe, but when using custom-webpack for both dev-server and browser, certain options in the browser build get ignored. I spent a lot of time trying to debug what’s going on (the devkit was very hard to debug), and it seems that when getTargetOptions is called within custom-webpack/dev-server, it includes the options, but when getTargetOptions is called again inside of executeDevServerBuilder
, it is missing some of the options specified.
This manifested for me with ‘showCircularDependencies’ (which is set to false for my browser build) getting ignored in the dev server build but respected in the browser build).]
This seems to repro pretty easily by simply calling getTargetOptions
twice inside of dev server, e.g.
async function setup() {
const browserTarget = targetFromTargetString(options.browserTarget);
const targetOptions1 = context.getTargetOptions(browserTarget).then(opts => // correct);
const targetOptions2 = context.getTargetOptions(browserTarget).then(opts => // missing some parameters)
return context.getTargetOptions(browserTarget) as unknown as CustomWebpackSchema;
}
I hope this is enough to investigate, I can provide more details as well
To Reproduce Steps to reproduce the behavior:
- Create a project that uses dev-server
- Add a non-default property to the browser build, e.g.
showCircularDependencies: false
- Target dev-server at build:browser
- Notice that the property showCircularDeps is ignored
Expected behavior Properties specified in the browser build are ignored
Libraries
@angular-builders/custom-webpack: "8.1.0"
@angular-devkit/architect: "0.802.0"
@angular-devkit/build-angular: "0.802.0"
@angular-devkit/build-optimizer: "0.802.0"
@angular/cli: "8.2.0"
@angular/compiler-cli: "8.2.0"
@angular/language-service: "8.2.0"
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:35 (14 by maintainers)
Top GitHub Comments
@flash-me the code (both Angular’s and custom-webpack’) seems completely fine to me. The custom config is still applied after the base one - note that the base one is passed to a transform, which, in turn, merges the config while the custom overrides the base.
Regarding the
if
, yes, you are right, this is for reason. If custom config exports a function, the base config is passed into this function and then the function is supposed to modify it and return the new config. It’s described in the docs.I’ll try to figure out why you’re getting this weird behavior, but from the first glance the code seems OK. One thing I need you to try though. If you run the dev-server build with
aot
the problem still persists?The problem here is that @angular-builders will apply its config onto the base webpack config. This was okay, because the CLI webpack-config has been applied before the custom one. But this Commit changed the behaviour.
On a quick look into the code I’d assume that using
mergeConfigs
in both cases might solve the issue, but I can image that there was a reason for theif
when providing a function. I donno 😕