From 444e20e5a1ff0417c863eae931288f1a191df329 Mon Sep 17 00:00:00 2001 From: Morten Rand-Hendriksen Date: Fri, 22 Mar 2019 15:12:58 -0700 Subject: [PATCH 1/2] 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. --- packages/scripts/README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index 111f5c61639c3c..73e58f1ac9a6ae 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -287,4 +287,28 @@ Should there be any situation where you want to provide your own webpack config, * the command receives a `--config` argument. Example: `wp-scripts build --config my-own-webpack-config.js`. * there is a file called `webpack.config.js` or `webpack.config.babel.js` in the top-level directory of your package (at the same level than your `package.json`). +##### Extending the webpack config + +To extend the provided webpack config, or replace subsections within the provided webpack config, you can provide your own `webpack.config.js` file, `require` the provided `webpack.config.js` file, and use the [`spread` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) to import all of or part of the provided configuration. + +In the example below, a `webpack.config.js` file is added to the root folder extending the provided webpack config to include [`@svgr/webpack`](https://www.npmjs.com/package/@svgr/webpack) and [`url-loader`](https://github.com/webpack-contrib/url-loader): + +```javascript +const defaultConfig = require("./node_modules/@wordpress/scripts/config/webpack.config"); + +module.exports = { + ...defaultConfig, + module: { + ...defaultConfig.module, + rules: [ + ...defaultConfig.module.rules, + { + test: /\.svg$/, + use: ["@svgr/webpack", "url-loader"] + } + ] + } +}; +``` +

Code is Poetry.

From fdaad9f8015eba8655a25e839bd0c25dbe0e7dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Mon, 25 Mar 2019 07:57:04 -0700 Subject: [PATCH 2/2] Update packages/scripts/README.md Co-Authored-By: mor10 --- packages/scripts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index 73e58f1ac9a6ae..16b22d3d7bfee9 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -310,5 +310,5 @@ module.exports = { } }; ``` - +If you follow this approach, please, be aware that future versions of this package may change what webpack and Babel plugins we bundle, default configs, etc. Should those changes be necessary, they will be registered in the [package's CHANGELOG](https://github.com/WordPress/gutenberg/blob/master/packages/scripts/CHANGELOG.md), so make sure to read it before upgrading.

Code is Poetry.