-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable extending webpack.config.js in packages/scripts/ #14560
Comments
You can totally extend the default config. Gutenberg does it already. I also did it yesterday in a plugin: ampproject/amp-wp#2000 |
Hmmmmmm. I must be doing something wrong then. Or maybe we're not talking about the same thing. |
@swissspidy can you point me at a basic example of extending the Webpack config with a single module? |
Here's how you import the config https://github.com/WordPress/gutenberg/blob/master/webpack.config.js#L16 and you can see a few lines after how it's reused. I hope this helps. |
Can I ask why using |
For me the most annoying part is the default |
@swissspidy What if we mimic parcel's api where we could do:
This would produce two scripts based on these two entry points? cc @gziolo |
I see this line imports default config used inside which is exactly the same solution as @youknowriad shared in Gutenberg context.
As always, we wanted to start with a very limited set of features and see how plugins use it before making further decisions. I want to play a bit more with In the case of Gutenberg, we have a new use case (#14497) where we would need to tweak an entry point, output folder, disable externals and probably handle CSS imports :) |
I don't know yet if we should implement a way to disable the externals, I'm not certain yet that this is something WordPress developpers would need. but yeah a "CSS build command" (to match Gutenberg build tools) would be a good idea. |
This looks relevant as an example: https://storybook.js.org/docs/configurations/custom-webpack-config/ |
See WordPress#14560. Adds explanation and code example for how to extend `webpack.config.js` using `spread` operator.
To help others who will have the same question I've proposed an update to the documentation complete with a simple code example. See #14590. |
* Add info on how to extend webpack.config.js See #14560. Adds explanation and code example for how to extend `webpack.config.js` using `spread` operator. * Update packages/scripts/README.md Co-Authored-By: mor10 <morten@pinkandyellow.com>
Unless I've totally misunderstood our build process, the proposed changes at #15226 pose an interesting related requirement in Gutenberg needing to opt-out of the default Babel processing. The most straight-forward option here is to unset all of the While simple rules could be done as such: module: {
rules: defaultConfig.module.rules.filter( ( rule ) => rule.use !== 'simple-loader' )
}, ...the current Babel loader configuration is a good example of a not-so-simple rule, and would be far more convoluted to exclude: gutenberg/packages/scripts/config/webpack.config.js Lines 37 to 60 in c8695f7
|
@aduth How can we extend these options for |
When using @wordpress/scripts, you can replace the existing
webpack.config.js
file with your own. It would be great if instead of having to build a full webpack config manually there was a way of extending the existing config to add a new module or similar. As an example, @svgr/webpack is useful in the context of blocks but using it means rewriting the entirewebpack.config.js
file.The text was updated successfully, but these errors were encountered: