const FileManagerPlugin = require( 'filemanager-webpack-plugin' ); const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); const path = require( 'path' ); const glob = require( 'glob' ); const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' ); const coreBlocks = files => glob .sync( files ) .reduce( ( entries, filename ) => { const [, name] = filename.match( /([^/]+)\.scss$/ ); return { ...entries, [ 'css/blocks/' + name ]: filename }; }, {} ); module.exports = { ...defaultConfig, module: { ...defaultConfig.module, }, entry: { ...defaultConfig.entry, style: path.resolve( process.cwd(), 'src', 'style.scss' ), ...coreBlocks( path.resolve( process.cwd(), 'src', 'scss/blocks/*.scss' ) ), }, plugins: [ ...defaultConfig.plugins, new RemoveEmptyScriptsPlugin(), new FileManagerPlugin( { events: { onEnd: { copy: [ { source: './build/style-style.css', destination: './build/style.css' } ], delete: [ './build/css/*.php', './build/css/*.js', './build/css/blocks/*.php', './build/css/blocks/*.js', './build/style-style.css' ], }, }, } ), ], };