Created
June 18, 2021 01:25
-
-
Save bosconian-dynamics/cc388797b5160f6acbb79983fcf697fc to your computer and use it in GitHub Desktop.
Webpack 4 Configurations to Build Multiple Gutenberg Blocks using @wordpress/scripts (see https://wordpress.stackexchange.com/q/390282/25324)
This file contains hidden or 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 path = require( 'path' ); | |
const config = require( '@wordpress/scripts/config/webpack.config.js' ); | |
const resolveSource = ( ...path_parts ) => path.resolve( process.cwd(), 'src', ...path_parts ); | |
const resolveBlockEntry = ( name ) => resolveSource( 'blocks', name, 'index.js' ); | |
config.entry = { | |
'blocks/foo/index': resolveBlockEntry( 'foo' ), | |
'blocks/bar/index': resolveBlockEntry( 'bar' ), | |
'frontend/accordion': resolveSource( 'frontend', 'accordion.js' ), | |
}; | |
config.optimization.splitChunks.cacheGroups.style.name = ( module, chunks, cache_group_key ) => { | |
const delimeter = config.optimization.splitChunks.cacheGroups.style.automaticNameDelimiter; | |
if( module.type === 'javascript/auto' ) | |
return `${cache_group_key}${delimeter}${chunks[0].name}`; | |
return chunks[0].name.replace( /(\/?)([^/]+?)$/, `$1style${delimeter}$2` ); | |
}; | |
module.exports = config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment