Closed yelhouti closed 1 year ago
Ok, so I did a little investigation and I have good news and bad news 😅 . The good news (mostly for me I guess) is that Custom Webpack builder works as expected and the configuration array goes all the way down to Angular Webpack abstraction.
The bad news is that Angular treats the configuration as an object, hence the issue. The error you get is:
An unhandled exception occurred: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration has an unknown property '0'.
And here is the root cause. See that little ...config
? That means they spread the object and add watch: false
to it. Which works well when it's indeed an object. But what happens when it's an array? Well, arrays are objects so when you spread it like object you'll get an object with properties 0
, 1
etc.
So after the spread the "config" would look like that:
{
'0': yourFirstConfig,
'1': yourSecondConfig,
watch: false
}
Which by no means is a Webpack config object. And that's why you get the error (which btw comes from Webpack schema validation).
Unfortunately there is not much you can do about it, except for opening an issue on Angular repo.
And even this would be a long shot IMO, because they treat Webpack as implementation details and they'll probably not support it.
From my side there is nothing I can do at all, but thanks for sharing an interesting use case.
@just-jeb thanks for taking the time, I guess I will add a postBuild step just for that, maybe its for the best.
Yup, good call 👍.
Describe the Bug
I am trying to compile a Workbox service worker written in typescript, I am using the
@angular-builders/custom-webpack:browser
project to do customize other parts of the build, and would like to run theworkbox-webpack-plugin
(withInjectManifest
).When I try to run the plugin inside the same config it fails because the angular build is not yet finished/ready. If I try to return two configs, using code that looks like this, it fails, because an array is not expected in the config.
Minimal Reproduction
https://github.com/yelhouti/angular-workbox
Expected Behavior
Angular should compile then workbox should get executed
Environment
Additional context
I would prefer to have the same config do everything so that when I run
ng serve --hmr
, the service worker is compiled and can be debugged ...