2023-03-31 17:36:40 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
|
|
|
|
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
|
|
|
|
const path = require( 'path' );
|
|
|
|
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );
|
|
|
|
const WebpackRTLPlugin = require( 'webpack-rtl-plugin' );
|
|
|
|
|
2023-01-31 13:38:28 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2024-02-27 08:07:53 +00:00
|
|
|
const {
|
|
|
|
webpackConfig,
|
|
|
|
StyleAssetPlugin,
|
|
|
|
} = require( '@woocommerce/internal-style-build' );
|
2023-03-31 17:36:40 +00:00
|
|
|
const {
|
|
|
|
blockEntryPoints,
|
|
|
|
getBlockMetaData,
|
|
|
|
getEntryPointName,
|
|
|
|
} = require( './config/block-entry-points' );
|
|
|
|
|
|
|
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
2023-01-31 13:38:28 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
mode: process.env.NODE_ENV || 'development',
|
|
|
|
entry: {
|
|
|
|
'build-style': __dirname + '/src/style.scss',
|
2023-03-31 17:36:40 +00:00
|
|
|
...blockEntryPoints,
|
2023-01-31 13:38:28 +00:00
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: __dirname,
|
|
|
|
},
|
|
|
|
module: {
|
2023-03-27 01:42:33 +00:00
|
|
|
parser: webpackConfig.parser,
|
2023-01-31 13:38:28 +00:00
|
|
|
rules: webpackConfig.rules,
|
|
|
|
},
|
2023-03-31 17:36:40 +00:00
|
|
|
plugins: [
|
|
|
|
new RemoveEmptyScriptsPlugin(),
|
|
|
|
new MiniCssExtractPlugin( {
|
|
|
|
filename: ( data ) => {
|
|
|
|
return data.chunk.name.startsWith( '/build/blocks' )
|
|
|
|
? `[name].css`
|
|
|
|
: `[name]/style.css`;
|
|
|
|
},
|
|
|
|
chunkFilename: 'chunks/[id].style.css',
|
|
|
|
} ),
|
|
|
|
new WebpackRTLPlugin( {
|
|
|
|
test: /(?<!style)\.css$/,
|
|
|
|
filename: '[name]-rtl.css',
|
|
|
|
minify: NODE_ENV === 'development' ? false : { safe: true },
|
|
|
|
} ),
|
|
|
|
new WebpackRTLPlugin( {
|
|
|
|
test: /style\.css$/,
|
|
|
|
filename: '[name]/style-rtl.css',
|
|
|
|
minify: NODE_ENV === 'development' ? false : { safe: true },
|
|
|
|
} ),
|
|
|
|
new CopyWebpackPlugin( {
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: './src/**/block.json',
|
|
|
|
to( { absoluteFilename } ) {
|
|
|
|
const blockMetaData = getBlockMetaData(
|
|
|
|
path.resolve( __dirname, absoluteFilename )
|
|
|
|
);
|
|
|
|
const entryPointName = getEntryPointName(
|
|
|
|
absoluteFilename,
|
|
|
|
blockMetaData
|
|
|
|
);
|
|
|
|
return `./${ entryPointName }`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} ),
|
2024-02-27 08:07:53 +00:00
|
|
|
new StyleAssetPlugin(),
|
2023-03-31 17:36:40 +00:00
|
|
|
],
|
2023-01-31 13:38:28 +00:00
|
|
|
};
|