Last active
May 21, 2024 18:21
-
-
Save silaskoehler/d2baa8320e3222f0d24ba301eb2ecfdb to your computer and use it in GitHub Desktop.
Example webpack config override when using --experimental-modules flag with wp-scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); | |
const { merge } = require( 'webpack-merge' ); | |
// get default configs | |
const [ scriptConfig, moduleConfig ] = defaultConfig; | |
/** | |
* Override script config | |
* the script config is the default config, which is used with or without the --experimental-modules flag | |
*/ | |
const scriptConfigOverride = { | |
// your configuration here | |
}; | |
/** | |
* Override modules config | |
* the module config is used for all scripts that are loaded via "viewScriptModule" in the block.json | |
*/ | |
const moduleConfigOverride = { | |
// your configuration here | |
}; | |
module.exports = [ | |
merge( scriptConfig, scriptConfigOverride ), | |
merge( moduleConfig, moduleConfigOverride ), | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Explanation:
viewScriptModule
property so it loads as an module (https://make.wordpress.org/core/2024/03/04/script-modules-in-6-5/).--experimental-modules
flagdefaultConfig
gives you an array with two objects inside and not an object.https://github.com/WordPress/gutenberg/blob/3a38dd82e9abff09747e1db0ae989b9d1cc67c84/packages/scripts/config/webpack.config.js#L469