2020-07-07 09:05:06 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const path = require( 'path' );
|
2022-08-01 14:57:33 +00:00
|
|
|
const fs = require( 'fs' );
|
2023-04-28 10:29:45 +00:00
|
|
|
const { paramCase } = require( 'change-case' );
|
2020-07-22 12:05:56 +00:00
|
|
|
const RemoveFilesPlugin = require( './remove-files-webpack-plugin' );
|
2020-07-07 09:05:06 +00:00
|
|
|
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
|
|
|
|
const ProgressBarPlugin = require( 'progress-bar-webpack-plugin' );
|
|
|
|
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
|
2023-09-20 20:31:52 +00:00
|
|
|
const WebpackRTLPlugin = require( './webpack-rtl-plugin' );
|
2021-06-29 11:18:29 +00:00
|
|
|
const TerserPlugin = require( 'terser-webpack-plugin' );
|
2020-07-07 09:05:06 +00:00
|
|
|
const CreateFileWebpack = require( 'create-file-webpack' );
|
2021-04-08 12:31:12 +00:00
|
|
|
const CircularDependencyPlugin = require( 'circular-dependency-plugin' );
|
2022-01-28 11:40:23 +00:00
|
|
|
const { BundleAnalyzerPlugin } = require( 'webpack-bundle-analyzer' );
|
2022-02-01 16:42:15 +00:00
|
|
|
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
|
2020-07-07 09:05:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
const { getEntryConfig } = require( './webpack-entries' );
|
|
|
|
const {
|
2022-02-02 14:56:16 +00:00
|
|
|
ASSET_CHECK,
|
2020-07-07 09:05:06 +00:00
|
|
|
NODE_ENV,
|
2021-04-08 12:31:12 +00:00
|
|
|
CHECK_CIRCULAR_DEPS,
|
2020-07-07 09:05:06 +00:00
|
|
|
requestToExternal,
|
|
|
|
requestToHandle,
|
2021-06-29 11:18:29 +00:00
|
|
|
getProgressBarPluginConfig,
|
2023-09-20 20:31:52 +00:00
|
|
|
getCacheGroups,
|
2020-07-07 09:05:06 +00:00
|
|
|
} = require( './webpack-helpers' );
|
|
|
|
|
2021-06-29 11:18:29 +00:00
|
|
|
const isProduction = NODE_ENV === 'production';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shared config for all script builds.
|
|
|
|
*/
|
2022-12-29 16:00:30 +00:00
|
|
|
let initialBundleAnalyzerPort = 8888;
|
2023-11-21 10:46:15 +00:00
|
|
|
const getSharedPlugins = ( {
|
|
|
|
bundleAnalyzerReportTitle,
|
|
|
|
checkCircularDeps = true,
|
|
|
|
} ) =>
|
2022-12-29 16:00:30 +00:00
|
|
|
[
|
2023-11-21 10:46:15 +00:00
|
|
|
CHECK_CIRCULAR_DEPS === 'true' && checkCircularDeps !== false
|
2022-12-29 16:00:30 +00:00
|
|
|
? new CircularDependencyPlugin( {
|
|
|
|
exclude: /node_modules/,
|
|
|
|
cwd: process.cwd(),
|
|
|
|
failOnError: 'warn',
|
|
|
|
} )
|
|
|
|
: false,
|
|
|
|
// The WP_BUNDLE_ANALYZER global variable enables a utility that represents bundle
|
|
|
|
// content as a convenient interactive zoomable treemap.
|
|
|
|
process.env.WP_BUNDLE_ANALYZER &&
|
|
|
|
new BundleAnalyzerPlugin( {
|
|
|
|
analyzerPort: initialBundleAnalyzerPort++,
|
|
|
|
reportTitle: bundleAnalyzerReportTitle,
|
|
|
|
} ),
|
|
|
|
new DependencyExtractionWebpackPlugin( {
|
|
|
|
injectPolyfill: true,
|
|
|
|
combineAssets: ASSET_CHECK,
|
|
|
|
outputFormat: ASSET_CHECK ? 'json' : 'php',
|
|
|
|
requestToExternal,
|
|
|
|
requestToHandle,
|
|
|
|
} ),
|
|
|
|
].filter( Boolean );
|
2020-07-07 09:05:06 +00:00
|
|
|
|
2021-06-29 11:18:29 +00:00
|
|
|
/**
|
|
|
|
* Build config for core packages.
|
|
|
|
*
|
|
|
|
* @param {Object} options Build options.
|
|
|
|
*/
|
2020-07-07 09:05:06 +00:00
|
|
|
const getCoreConfig = ( options = {} ) => {
|
2021-01-07 12:02:21 +00:00
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
const resolve = alias
|
|
|
|
? {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
};
|
2020-07-07 09:05:06 +00:00
|
|
|
return {
|
|
|
|
entry: getEntryConfig( 'core', options.exclude || [] ),
|
|
|
|
output: {
|
|
|
|
filename: ( chunkData ) => {
|
2023-04-28 10:29:45 +00:00
|
|
|
return `${ paramCase( chunkData.chunk.name ) }.js`;
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
2023-12-10 06:35:11 +00:00
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
2020-07-07 09:05:06 +00:00
|
|
|
library: [ 'wc', '[name]' ],
|
|
|
|
libraryTarget: 'this',
|
2023-09-20 20:31:52 +00:00
|
|
|
uniqueName: 'webpackWcBlocksJsonp',
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2021-02-24 01:36:24 +00:00
|
|
|
test: /\.(t|j)sx?$/,
|
2020-07-07 09:05:06 +00:00
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
2023-09-20 20:31:52 +00:00
|
|
|
loader: 'babel-loader',
|
2020-07-07 09:05:06 +00:00
|
|
|
options: {
|
|
|
|
presets: [ '@wordpress/babel-preset-default' ],
|
2023-07-26 09:58:17 +00:00
|
|
|
plugins: [
|
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
],
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-01-07 12:02:21 +00:00
|
|
|
{
|
|
|
|
test: /\.s[c|a]ss$/,
|
|
|
|
use: {
|
|
|
|
loader: 'ignore-loader',
|
|
|
|
},
|
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
2022-12-29 16:00:30 +00:00
|
|
|
...getSharedPlugins( { bundleAnalyzerReportTitle: 'Core' } ),
|
2022-12-22 16:04:54 +00:00
|
|
|
new ProgressBarPlugin( getProgressBarPluginConfig( 'Core' ) ),
|
2020-07-07 09:05:06 +00:00
|
|
|
new CreateFileWebpack( {
|
2023-12-10 06:35:11 +00:00
|
|
|
path: './',
|
2020-07-07 09:05:06 +00:00
|
|
|
// file name
|
|
|
|
fileName: 'blocks.ini',
|
|
|
|
// content of the file
|
2021-01-20 19:33:50 +00:00
|
|
|
content: `
|
|
|
|
woocommerce_blocks_phase = ${ process.env.WOOCOMMERCE_BLOCKS_PHASE || 3 }
|
|
|
|
woocommerce_blocks_env = ${ NODE_ENV }
|
|
|
|
`.trim(),
|
2020-07-07 09:05:06 +00:00
|
|
|
} ),
|
|
|
|
],
|
2021-06-29 11:18:29 +00:00
|
|
|
optimization: {
|
2022-01-28 11:40:23 +00:00
|
|
|
// Only concatenate modules in production, when not analyzing bundles.
|
|
|
|
concatenateModules:
|
|
|
|
isProduction && ! process.env.WP_BUNDLE_ANALYZER,
|
2022-05-25 15:59:51 +00:00
|
|
|
splitChunks: {
|
|
|
|
automaticNameDelimiter: '--',
|
2023-09-20 20:31:52 +00:00
|
|
|
cacheGroups: {
|
|
|
|
...getCacheGroups(),
|
|
|
|
},
|
2022-05-25 15:59:51 +00:00
|
|
|
},
|
2021-06-29 11:18:29 +00:00
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin( {
|
|
|
|
parallel: true,
|
|
|
|
terserOptions: {
|
|
|
|
output: {
|
|
|
|
comments: /translators:/i,
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
passes: 2,
|
|
|
|
},
|
|
|
|
mangle: {
|
|
|
|
reserved: [ '__', '_n', '_nx', '_x' ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
extractComments: false,
|
|
|
|
} ),
|
|
|
|
],
|
|
|
|
},
|
2021-02-24 01:36:24 +00:00
|
|
|
resolve: {
|
|
|
|
...resolve,
|
|
|
|
extensions: [ '.js', '.ts', '.tsx' ],
|
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
};
|
|
|
|
};
|
2021-06-29 11:18:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Build config for Blocks in the editor context.
|
|
|
|
*
|
|
|
|
* @param {Object} options Build options.
|
|
|
|
*/
|
2020-07-07 09:05:06 +00:00
|
|
|
const getMainConfig = ( options = {} ) => {
|
|
|
|
let { fileSuffix } = options;
|
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
fileSuffix = fileSuffix ? `-${ fileSuffix }` : '';
|
|
|
|
const resolve = alias
|
|
|
|
? {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
entry: getEntryConfig( 'main', options.exclude || [] ),
|
|
|
|
output: {
|
|
|
|
devtoolNamespace: 'wc',
|
2023-12-10 06:35:11 +00:00
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
2021-11-09 15:10:47 +00:00
|
|
|
// This is a cache busting mechanism which ensures that the script is loaded via the browser with a ?ver=hash
|
|
|
|
// string. The hash is based on the built file contents.
|
|
|
|
// @see https://github.com/webpack/webpack/issues/2329
|
|
|
|
// Using the ?ver string is needed here so the filename does not change between builds. The WordPress
|
|
|
|
// i18n system relies on the hash of the filename, so changing that frequently would result in broken
|
|
|
|
// translations which we must avoid.
|
|
|
|
// @see https://github.com/Automattic/jetpack/pull/20926
|
|
|
|
chunkFilename: `[name]${ fileSuffix }.js?ver=[contenthash]`,
|
2020-07-07 09:05:06 +00:00
|
|
|
filename: `[name]${ fileSuffix }.js`,
|
|
|
|
library: [ 'wc', 'blocks', '[name]' ],
|
|
|
|
libraryTarget: 'this',
|
2023-09-20 20:31:52 +00:00
|
|
|
uniqueName: 'webpackWcBlocksJsonp',
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2021-02-24 01:36:24 +00:00
|
|
|
test: /\.(j|t)sx?$/,
|
2020-07-07 09:05:06 +00:00
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
2023-09-20 20:31:52 +00:00
|
|
|
loader: 'babel-loader',
|
2020-07-07 09:05:06 +00:00
|
|
|
options: {
|
|
|
|
presets: [ '@wordpress/babel-preset-default' ],
|
|
|
|
plugins: [
|
2021-06-29 11:18:29 +00:00
|
|
|
isProduction
|
2020-07-07 09:05:06 +00:00
|
|
|
? require.resolve(
|
|
|
|
'babel-plugin-transform-react-remove-prop-types'
|
|
|
|
)
|
|
|
|
: false,
|
2023-07-26 09:58:17 +00:00
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
2020-07-07 09:05:06 +00:00
|
|
|
].filter( Boolean ),
|
2023-09-20 20:31:52 +00:00
|
|
|
cacheDirectory: true,
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-07-22 12:05:56 +00:00
|
|
|
test: /\.s[c|a]ss$/,
|
|
|
|
use: {
|
|
|
|
loader: 'ignore-loader',
|
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-06-29 11:18:29 +00:00
|
|
|
optimization: {
|
2022-01-28 11:40:23 +00:00
|
|
|
concatenateModules:
|
|
|
|
isProduction && ! process.env.WP_BUNDLE_ANALYZER,
|
2021-06-29 11:18:29 +00:00
|
|
|
splitChunks: {
|
2023-09-20 20:31:52 +00:00
|
|
|
minSize: 200000,
|
2021-06-29 11:18:29 +00:00
|
|
|
automaticNameDelimiter: '--',
|
|
|
|
cacheGroups: {
|
|
|
|
commons: {
|
2022-11-02 10:24:19 +00:00
|
|
|
test: /[\/\\]node_modules[\/\\]/,
|
2021-06-29 11:18:29 +00:00
|
|
|
name: 'wc-blocks-vendors',
|
|
|
|
chunks: 'all',
|
|
|
|
enforce: true,
|
|
|
|
},
|
2023-09-20 20:31:52 +00:00
|
|
|
...getCacheGroups(),
|
2021-06-29 11:18:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin( {
|
|
|
|
parallel: true,
|
|
|
|
terserOptions: {
|
|
|
|
output: {
|
|
|
|
comments: /translators:/i,
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
passes: 2,
|
|
|
|
},
|
|
|
|
mangle: {
|
|
|
|
reserved: [ '__', '_n', '_nx', '_x' ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
extractComments: false,
|
|
|
|
} ),
|
|
|
|
],
|
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
plugins: [
|
2022-12-29 16:00:30 +00:00
|
|
|
...getSharedPlugins( { bundleAnalyzerReportTitle: 'Main' } ),
|
2022-12-22 16:04:54 +00:00
|
|
|
new ProgressBarPlugin( getProgressBarPluginConfig( 'Main' ) ),
|
2022-02-01 16:42:15 +00:00
|
|
|
new CopyWebpackPlugin( {
|
|
|
|
patterns: [
|
|
|
|
{
|
2022-08-18 08:02:21 +00:00
|
|
|
from: './assets/js/**/block.json',
|
2022-06-09 14:45:24 +00:00
|
|
|
to( { absoluteFilename } ) {
|
2022-08-01 14:57:33 +00:00
|
|
|
/**
|
|
|
|
* Getting the block name from the JSON metadata is less error prone
|
|
|
|
* than extracting it from the file path.
|
|
|
|
*/
|
|
|
|
const JSONFile = fs.readFileSync(
|
|
|
|
path.resolve( __dirname, absoluteFilename )
|
|
|
|
);
|
|
|
|
const metadata = JSON.parse( JSONFile.toString() );
|
|
|
|
const blockName = metadata.name
|
2022-06-09 14:45:24 +00:00
|
|
|
.split( '/' )
|
2022-08-01 14:57:33 +00:00
|
|
|
.at( 1 );
|
2022-09-26 14:02:36 +00:00
|
|
|
|
|
|
|
if ( metadata.parent )
|
|
|
|
return `./inner-blocks/${ blockName }/block.json`;
|
2022-06-09 14:45:24 +00:00
|
|
|
return `./${ blockName }/block.json`;
|
|
|
|
},
|
2022-05-23 08:10:06 +00:00
|
|
|
},
|
2022-02-01 16:42:15 +00:00
|
|
|
],
|
|
|
|
} ),
|
2020-07-07 09:05:06 +00:00
|
|
|
],
|
2021-02-24 01:36:24 +00:00
|
|
|
resolve: {
|
|
|
|
...resolve,
|
2021-05-20 08:58:59 +00:00
|
|
|
extensions: [ '.js', '.jsx', '.ts', '.tsx' ],
|
2021-02-24 01:36:24 +00:00
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-06-29 11:18:29 +00:00
|
|
|
/**
|
|
|
|
* Build config for Blocks in the frontend context.
|
|
|
|
*
|
|
|
|
* @param {Object} options Build options.
|
|
|
|
*/
|
2020-07-07 09:05:06 +00:00
|
|
|
const getFrontConfig = ( options = {} ) => {
|
|
|
|
let { fileSuffix } = options;
|
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
fileSuffix = fileSuffix ? `-${ fileSuffix }` : '';
|
|
|
|
const resolve = alias
|
|
|
|
? {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
entry: getEntryConfig( 'frontend', options.exclude || [] ),
|
|
|
|
output: {
|
|
|
|
devtoolNamespace: 'wc',
|
2023-12-10 06:35:11 +00:00
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
2021-11-09 15:10:47 +00:00
|
|
|
// This is a cache busting mechanism which ensures that the script is loaded via the browser with a ?ver=hash
|
|
|
|
// string. The hash is based on the built file contents.
|
|
|
|
// @see https://github.com/webpack/webpack/issues/2329
|
|
|
|
// Using the ?ver string is needed here so the filename does not change between builds. The WordPress
|
|
|
|
// i18n system relies on the hash of the filename, so changing that frequently would result in broken
|
|
|
|
// translations which we must avoid.
|
|
|
|
// @see https://github.com/Automattic/jetpack/pull/20926
|
|
|
|
chunkFilename: `[name]-frontend${ fileSuffix }.js?ver=[contenthash]`,
|
2020-07-07 09:05:06 +00:00
|
|
|
filename: `[name]-frontend${ fileSuffix }.js`,
|
2023-09-20 20:31:52 +00:00
|
|
|
uniqueName: 'webpackWcBlocksJsonp',
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2021-02-24 01:36:24 +00:00
|
|
|
test: /\.(j|t)sx?$/,
|
2020-07-07 09:05:06 +00:00
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
2023-09-20 20:31:52 +00:00
|
|
|
loader: 'babel-loader',
|
2020-07-07 09:05:06 +00:00
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
[
|
2021-11-23 14:49:35 +00:00
|
|
|
'@wordpress/babel-preset-default',
|
2020-07-07 09:05:06 +00:00
|
|
|
{
|
|
|
|
modules: false,
|
|
|
|
targets: {
|
|
|
|
browsers: [
|
|
|
|
'extends @wordpress/browserslist-config',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
plugins: [
|
2021-06-29 11:18:29 +00:00
|
|
|
isProduction
|
2020-07-07 09:05:06 +00:00
|
|
|
? require.resolve(
|
|
|
|
'babel-plugin-transform-react-remove-prop-types'
|
|
|
|
)
|
|
|
|
: false,
|
2023-07-26 09:58:17 +00:00
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
2020-07-07 09:05:06 +00:00
|
|
|
].filter( Boolean ),
|
2023-09-20 20:31:52 +00:00
|
|
|
cacheDirectory: true,
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s[c|a]ss$/,
|
|
|
|
use: {
|
|
|
|
loader: 'ignore-loader',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-06-29 11:18:29 +00:00
|
|
|
optimization: {
|
2022-01-28 11:40:23 +00:00
|
|
|
concatenateModules:
|
|
|
|
isProduction && ! process.env.WP_BUNDLE_ANALYZER,
|
2021-06-29 11:18:29 +00:00
|
|
|
splitChunks: {
|
2023-09-20 20:31:52 +00:00
|
|
|
minSize: 200000,
|
2022-05-25 15:59:51 +00:00
|
|
|
automaticNameDelimiter: '--',
|
2023-09-20 20:31:52 +00:00
|
|
|
cacheGroups: {
|
|
|
|
...getCacheGroups(),
|
|
|
|
'base-components': {
|
|
|
|
test: /\/assets\/js\/base\/components\//,
|
|
|
|
name( module, chunks, cacheGroupKey ) {
|
|
|
|
const moduleFileName = module
|
|
|
|
.identifier()
|
|
|
|
.split( '/' )
|
|
|
|
.reduceRight( ( item ) => item );
|
|
|
|
const allChunksNames = chunks
|
|
|
|
.map( ( item ) => item.name )
|
|
|
|
.join( '~' );
|
|
|
|
return `${ cacheGroupKey }-${ allChunksNames }-${ moduleFileName }`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-06-29 11:18:29 +00:00
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin( {
|
|
|
|
parallel: true,
|
|
|
|
terserOptions: {
|
|
|
|
output: {
|
|
|
|
comments: /translators:/i,
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
passes: 2,
|
|
|
|
},
|
|
|
|
mangle: {
|
|
|
|
reserved: [ '__', '_n', '_nx', '_x' ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
extractComments: false,
|
|
|
|
} ),
|
|
|
|
],
|
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
plugins: [
|
2022-12-29 16:00:30 +00:00
|
|
|
...getSharedPlugins( { bundleAnalyzerReportTitle: 'Frontend' } ),
|
2022-12-22 16:04:54 +00:00
|
|
|
new ProgressBarPlugin( getProgressBarPluginConfig( 'Frontend' ) ),
|
2020-07-07 09:05:06 +00:00
|
|
|
],
|
2021-02-24 01:36:24 +00:00
|
|
|
resolve: {
|
|
|
|
...resolve,
|
|
|
|
extensions: [ '.js', '.ts', '.tsx' ],
|
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-06-29 11:18:29 +00:00
|
|
|
/**
|
|
|
|
* Build config for built-in payment gateway integrations.
|
|
|
|
*
|
|
|
|
* @param {Object} options Build options.
|
|
|
|
*/
|
2020-07-07 09:05:06 +00:00
|
|
|
const getPaymentsConfig = ( options = {} ) => {
|
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
const resolve = alias
|
|
|
|
? {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
entry: getEntryConfig( 'payments', options.exclude || [] ),
|
|
|
|
output: {
|
|
|
|
devtoolNamespace: 'wc',
|
2023-12-10 06:35:11 +00:00
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
2020-07-07 09:05:06 +00:00
|
|
|
filename: `[name].js`,
|
2023-09-20 20:31:52 +00:00
|
|
|
uniqueName: 'webpackWcBlocksPaymentMethodExtensionJsonp',
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2021-02-24 01:36:24 +00:00
|
|
|
test: /\.(j|t)sx?$/,
|
2020-07-07 09:05:06 +00:00
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
2023-09-20 20:31:52 +00:00
|
|
|
loader: 'babel-loader',
|
2020-07-07 09:05:06 +00:00
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
[
|
2021-11-23 14:49:35 +00:00
|
|
|
'@wordpress/babel-preset-default',
|
2020-07-07 09:05:06 +00:00
|
|
|
{
|
|
|
|
modules: false,
|
|
|
|
targets: {
|
|
|
|
browsers: [
|
|
|
|
'extends @wordpress/browserslist-config',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
plugins: [
|
2021-06-29 11:18:29 +00:00
|
|
|
isProduction
|
2020-07-07 09:05:06 +00:00
|
|
|
? require.resolve(
|
|
|
|
'babel-plugin-transform-react-remove-prop-types'
|
|
|
|
)
|
|
|
|
: false,
|
2023-07-26 09:58:17 +00:00
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
2020-07-07 09:05:06 +00:00
|
|
|
].filter( Boolean ),
|
2023-09-20 20:31:52 +00:00
|
|
|
cacheDirectory: true,
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-07-22 12:05:56 +00:00
|
|
|
{
|
|
|
|
test: /\.s[c|a]ss$/,
|
|
|
|
use: {
|
|
|
|
loader: 'ignore-loader',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-06-29 11:18:29 +00:00
|
|
|
optimization: {
|
2022-01-28 11:40:23 +00:00
|
|
|
concatenateModules:
|
|
|
|
isProduction && ! process.env.WP_BUNDLE_ANALYZER,
|
2021-06-29 11:18:29 +00:00
|
|
|
splitChunks: {
|
|
|
|
automaticNameDelimiter: '--',
|
2023-09-20 20:31:52 +00:00
|
|
|
cacheGroups: {
|
|
|
|
...getCacheGroups(),
|
|
|
|
},
|
2021-06-29 11:18:29 +00:00
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin( {
|
|
|
|
parallel: true,
|
|
|
|
terserOptions: {
|
|
|
|
output: {
|
|
|
|
comments: /translators:/i,
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
passes: 2,
|
|
|
|
},
|
|
|
|
mangle: {
|
|
|
|
reserved: [ '__', '_n', '_nx', '_x' ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
extractComments: false,
|
|
|
|
} ),
|
|
|
|
],
|
|
|
|
},
|
2020-07-22 12:05:56 +00:00
|
|
|
plugins: [
|
2022-12-29 16:00:30 +00:00
|
|
|
...getSharedPlugins( {
|
|
|
|
bundleAnalyzerReportTitle: 'Payment Method Extensions',
|
|
|
|
} ),
|
2020-07-22 12:05:56 +00:00
|
|
|
new ProgressBarPlugin(
|
2022-12-22 16:04:54 +00:00
|
|
|
getProgressBarPluginConfig( 'Payment Method Extensions' )
|
2020-07-22 12:05:56 +00:00
|
|
|
),
|
|
|
|
],
|
2021-02-24 01:36:24 +00:00
|
|
|
resolve: {
|
|
|
|
...resolve,
|
|
|
|
extensions: [ '.js', '.ts', '.tsx' ],
|
|
|
|
},
|
2020-07-22 12:05:56 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-06-29 11:18:29 +00:00
|
|
|
/**
|
|
|
|
* Build config for extension integrations.
|
|
|
|
*
|
|
|
|
* @param {Object} options Build options.
|
|
|
|
*/
|
2021-03-16 11:40:22 +00:00
|
|
|
const getExtensionsConfig = ( options = {} ) => {
|
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
const resolve = alias
|
|
|
|
? {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
entry: getEntryConfig( 'extensions', options.exclude || [] ),
|
|
|
|
output: {
|
|
|
|
devtoolNamespace: 'wc',
|
2023-12-10 06:35:11 +00:00
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
2021-03-16 11:40:22 +00:00
|
|
|
filename: `[name].js`,
|
2023-09-20 20:31:52 +00:00
|
|
|
uniqueName: 'webpackWcBlocksExtensionsMethodExtensionJsonp',
|
2021-03-16 11:40:22 +00:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(j|t)sx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
2023-09-20 20:31:52 +00:00
|
|
|
loader: 'babel-loader',
|
2021-03-16 11:40:22 +00:00
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
[
|
2021-11-23 14:49:35 +00:00
|
|
|
'@wordpress/babel-preset-default',
|
2021-03-16 11:40:22 +00:00
|
|
|
{
|
|
|
|
modules: false,
|
|
|
|
targets: {
|
|
|
|
browsers: [
|
|
|
|
'extends @wordpress/browserslist-config',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
plugins: [
|
2021-06-29 11:18:29 +00:00
|
|
|
isProduction
|
2021-03-16 11:40:22 +00:00
|
|
|
? require.resolve(
|
|
|
|
'babel-plugin-transform-react-remove-prop-types'
|
|
|
|
)
|
|
|
|
: false,
|
2023-07-26 09:58:17 +00:00
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
2021-03-16 11:40:22 +00:00
|
|
|
].filter( Boolean ),
|
2023-09-20 20:31:52 +00:00
|
|
|
cacheDirectory: true,
|
2021-03-16 11:40:22 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-11-11 16:17:49 +00:00
|
|
|
{
|
|
|
|
test: /\.s[c|a]ss$/,
|
|
|
|
use: {
|
|
|
|
loader: 'ignore-loader',
|
|
|
|
},
|
|
|
|
},
|
2021-03-16 11:40:22 +00:00
|
|
|
],
|
|
|
|
},
|
2021-06-29 11:18:29 +00:00
|
|
|
optimization: {
|
2022-01-28 11:40:23 +00:00
|
|
|
concatenateModules:
|
|
|
|
isProduction && ! process.env.WP_BUNDLE_ANALYZER,
|
2021-06-29 11:18:29 +00:00
|
|
|
splitChunks: {
|
|
|
|
automaticNameDelimiter: '--',
|
2023-09-20 20:31:52 +00:00
|
|
|
cacheGroups: {
|
|
|
|
...getCacheGroups(),
|
|
|
|
},
|
2021-06-29 11:18:29 +00:00
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin( {
|
|
|
|
parallel: true,
|
|
|
|
terserOptions: {
|
|
|
|
output: {
|
|
|
|
comments: /translators:/i,
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
passes: 2,
|
|
|
|
},
|
|
|
|
mangle: {
|
|
|
|
reserved: [ '__', '_n', '_nx', '_x' ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
extractComments: false,
|
|
|
|
} ),
|
|
|
|
],
|
|
|
|
},
|
2021-03-16 11:40:22 +00:00
|
|
|
plugins: [
|
2022-12-29 16:00:30 +00:00
|
|
|
...getSharedPlugins( {
|
|
|
|
bundleAnalyzerReportTitle: 'Experimental Extensions',
|
|
|
|
} ),
|
2021-03-16 11:40:22 +00:00
|
|
|
new ProgressBarPlugin(
|
2022-12-22 16:04:54 +00:00
|
|
|
getProgressBarPluginConfig( 'Experimental Extensions' )
|
2021-03-16 11:40:22 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
...resolve,
|
2021-06-29 11:18:29 +00:00
|
|
|
extensions: [ '.js', '.ts', '.tsx' ],
|
2021-03-16 11:40:22 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-07-31 07:03:10 +00:00
|
|
|
/**
|
|
|
|
* Build config for scripts to be used exclusively within the Site Editor context.
|
|
|
|
*
|
|
|
|
* @param {Object} options Build options.
|
|
|
|
*/
|
|
|
|
const getSiteEditorConfig = ( options = {} ) => {
|
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
const resolve = alias
|
|
|
|
? {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
entry: getEntryConfig( 'editor', options.exclude || [] ),
|
|
|
|
output: {
|
|
|
|
devtoolNamespace: 'wc',
|
2023-12-10 06:35:11 +00:00
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
2023-07-31 07:03:10 +00:00
|
|
|
filename: `[name].js`,
|
2023-09-20 20:31:52 +00:00
|
|
|
chunkLoadingGlobal: 'webpackWcBlocksExtensionsMethodExtensionJsonp',
|
2023-07-31 07:03:10 +00:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(j|t)sx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
'@wordpress/babel-preset-default',
|
|
|
|
{
|
|
|
|
modules: false,
|
|
|
|
targets: {
|
|
|
|
browsers: [
|
|
|
|
'extends @wordpress/browserslist-config',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
isProduction
|
|
|
|
? require.resolve(
|
|
|
|
'babel-plugin-transform-react-remove-prop-types'
|
|
|
|
)
|
|
|
|
: false,
|
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
|
|
|
].filter( Boolean ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s[c|a]ss$/,
|
|
|
|
use: {
|
|
|
|
loader: 'ignore-loader',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
concatenateModules:
|
|
|
|
isProduction && ! process.env.WP_BUNDLE_ANALYZER,
|
|
|
|
splitChunks: {
|
|
|
|
automaticNameDelimiter: '--',
|
2023-09-20 20:31:52 +00:00
|
|
|
cacheGroups: {
|
|
|
|
...getCacheGroups(),
|
|
|
|
},
|
2023-07-31 07:03:10 +00:00
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin( {
|
|
|
|
parallel: true,
|
|
|
|
terserOptions: {
|
|
|
|
output: {
|
|
|
|
comments: /translators:/i,
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
passes: 2,
|
|
|
|
},
|
|
|
|
mangle: {
|
|
|
|
reserved: [ '__', '_n', '_nx', '_x' ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
extractComments: false,
|
|
|
|
} ),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
...getSharedPlugins( {
|
|
|
|
bundleAnalyzerReportTitle: 'Site Editor',
|
|
|
|
} ),
|
|
|
|
new ProgressBarPlugin(
|
|
|
|
getProgressBarPluginConfig( 'Site Editor' )
|
|
|
|
),
|
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
...resolve,
|
|
|
|
extensions: [ '.js', '.ts', '.tsx' ],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-06-29 11:18:29 +00:00
|
|
|
/**
|
|
|
|
* Build config for CSS Styles.
|
|
|
|
*
|
|
|
|
* @param {Object} options Build options.
|
|
|
|
*/
|
2020-07-22 12:05:56 +00:00
|
|
|
const getStylingConfig = ( options = {} ) => {
|
2023-09-08 04:15:48 +00:00
|
|
|
let { fileSuffix } = options;
|
2020-07-22 12:05:56 +00:00
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
fileSuffix = fileSuffix ? `-${ fileSuffix }` : '';
|
|
|
|
const resolve = alias
|
|
|
|
? {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
entry: getEntryConfig( 'styling', options.exclude || [] ),
|
|
|
|
output: {
|
|
|
|
devtoolNamespace: 'wc',
|
2023-12-10 06:35:11 +00:00
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
2020-07-22 12:05:56 +00:00
|
|
|
filename: `[name]-style${ fileSuffix }.js`,
|
|
|
|
library: [ 'wc', 'blocks', '[name]' ],
|
|
|
|
libraryTarget: 'this',
|
2023-09-20 20:31:52 +00:00
|
|
|
uniqueName: 'webpackWcBlocksJsonp',
|
2020-07-22 12:05:56 +00:00
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
2020-11-09 10:44:58 +00:00
|
|
|
automaticNameDelimiter: '--',
|
2020-07-22 12:05:56 +00:00
|
|
|
cacheGroups: {
|
2021-06-09 14:09:42 +00:00
|
|
|
editorStyle: {
|
2020-09-02 08:21:46 +00:00
|
|
|
// Capture all `editor` stylesheets and editor-components stylesheets.
|
2023-09-20 20:31:52 +00:00
|
|
|
test: ( module = {}, { moduleGraph } ) => {
|
|
|
|
if ( ! module.type.includes( 'css' ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const moduleIssuer =
|
|
|
|
moduleGraph.getIssuer( module );
|
|
|
|
if ( ! moduleIssuer ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
moduleIssuer.resource.endsWith(
|
|
|
|
'editor.scss'
|
|
|
|
) ||
|
|
|
|
moduleIssuer.resource.includes(
|
|
|
|
`${ path.sep }assets${ path.sep }js${ path.sep }editor-components${ path.sep }`
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
2021-06-09 14:09:42 +00:00
|
|
|
name: 'wc-blocks-editor-style',
|
2020-07-22 12:05:56 +00:00
|
|
|
chunks: 'all',
|
|
|
|
priority: 10,
|
|
|
|
},
|
2023-09-20 20:31:52 +00:00
|
|
|
...getCacheGroups(),
|
|
|
|
'base-components': {
|
|
|
|
test: /\/assets\/js\/base\/components\//,
|
|
|
|
name( module, chunks, cacheGroupKey ) {
|
|
|
|
const moduleFileName = module
|
|
|
|
.identifier()
|
|
|
|
.split( '/' )
|
|
|
|
.reduceRight( ( item ) => item )
|
|
|
|
.split( '|' )
|
|
|
|
.reduce( ( item ) => item );
|
|
|
|
const allChunksNames = chunks
|
|
|
|
.map( ( item ) => item.name )
|
|
|
|
.join( '~' );
|
|
|
|
return `${ cacheGroupKey }-${ allChunksNames }-${ moduleFileName }`;
|
|
|
|
},
|
|
|
|
},
|
2020-07-22 12:05:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2023-07-04 11:06:48 +00:00
|
|
|
test: /\.(j|t)sx?$/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
|
|
|
presets: [ '@wordpress/babel-preset-default' ],
|
|
|
|
plugins: [
|
|
|
|
isProduction
|
|
|
|
? require.resolve(
|
|
|
|
'babel-plugin-transform-react-remove-prop-types'
|
|
|
|
)
|
|
|
|
: false,
|
2023-07-26 09:58:17 +00:00
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
2023-07-04 11:06:48 +00:00
|
|
|
].filter( Boolean ),
|
2020-07-22 12:05:56 +00:00
|
|
|
},
|
2023-07-04 11:06:48 +00:00
|
|
|
},
|
2020-07-22 12:05:56 +00:00
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
2023-07-04 11:06:48 +00:00
|
|
|
'css-loader',
|
2020-07-07 09:05:06 +00:00
|
|
|
'postcss-loader',
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
2021-01-07 12:40:00 +00:00
|
|
|
options: {
|
|
|
|
sassOptions: {
|
|
|
|
includePaths: [ 'assets/css/abstracts' ],
|
|
|
|
},
|
|
|
|
additionalData: ( content, loaderContext ) => {
|
2022-06-15 09:56:52 +00:00
|
|
|
const { resourcePath, rootContext } =
|
|
|
|
loaderContext;
|
2021-01-07 12:40:00 +00:00
|
|
|
const relativePath = path.relative(
|
|
|
|
rootContext,
|
|
|
|
resourcePath
|
|
|
|
);
|
|
|
|
|
|
|
|
if (
|
|
|
|
relativePath.startsWith(
|
|
|
|
'assets/css/abstracts/'
|
2022-11-02 10:24:19 +00:00
|
|
|
) ||
|
|
|
|
relativePath.startsWith(
|
|
|
|
'assets\\css\\abstracts\\'
|
2021-01-07 12:40:00 +00:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-08-24 11:37:43 +00:00
|
|
|
'@use "sass:math";' +
|
2022-03-28 13:00:20 +00:00
|
|
|
'@use "sass:string";' +
|
|
|
|
'@use "sass:color";' +
|
|
|
|
'@use "sass:map";' +
|
2021-01-07 12:40:00 +00:00
|
|
|
'@import "_colors"; ' +
|
|
|
|
'@import "_variables"; ' +
|
|
|
|
'@import "_breakpoints"; ' +
|
|
|
|
'@import "_mixins"; ' +
|
|
|
|
content
|
|
|
|
);
|
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
2023-07-04 11:06:48 +00:00
|
|
|
...getSharedPlugins( { bundleAnalyzerReportTitle: 'Styles' } ),
|
2022-12-22 16:04:54 +00:00
|
|
|
new ProgressBarPlugin( getProgressBarPluginConfig( 'Styles' ) ),
|
2020-07-07 09:05:06 +00:00
|
|
|
new MiniCssExtractPlugin( {
|
2020-07-22 12:05:56 +00:00
|
|
|
filename: `[name]${ fileSuffix }.css`,
|
2020-07-07 09:05:06 +00:00
|
|
|
} ),
|
2023-09-20 20:31:52 +00:00
|
|
|
new WebpackRTLPlugin( {
|
|
|
|
filenameSuffix: '-rtl.css',
|
|
|
|
} ),
|
2020-07-22 12:05:56 +00:00
|
|
|
// Remove JS files generated by MiniCssExtractPlugin.
|
|
|
|
new RemoveFilesPlugin( `./build/*style${ fileSuffix }.js` ),
|
2020-07-07 09:05:06 +00:00
|
|
|
],
|
2021-02-24 01:36:24 +00:00
|
|
|
resolve: {
|
|
|
|
...resolve,
|
2023-07-04 11:06:48 +00:00
|
|
|
extensions: [ '.js', '.jsx', '.ts', '.tsx' ],
|
2021-02-24 01:36:24 +00:00
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-01-26 11:39:25 +00:00
|
|
|
const getInteractivityAPIConfig = ( options = {} ) => {
|
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
return {
|
|
|
|
entry: {
|
2023-06-27 10:22:12 +00:00
|
|
|
'wc-interactivity': './assets/js/interactivity',
|
2023-01-26 11:39:25 +00:00
|
|
|
},
|
|
|
|
output: {
|
2023-06-27 10:22:12 +00:00
|
|
|
filename: '[name].js',
|
2023-12-10 06:35:11 +00:00
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
2023-06-27 10:22:12 +00:00
|
|
|
library: [ 'wc', '__experimentalInteractivity' ],
|
|
|
|
libraryTarget: 'this',
|
2023-09-20 20:31:52 +00:00
|
|
|
chunkLoadingGlobal: 'webpackWcBlocksJsonp',
|
2023-01-26 11:39:25 +00:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
extensions: [ '.js', '.ts', '.tsx' ],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
...getSharedPlugins( {
|
|
|
|
bundleAnalyzerReportTitle: 'WP directives',
|
2023-11-21 10:46:15 +00:00
|
|
|
checkCircularDeps: false,
|
2023-01-26 11:39:25 +00:00
|
|
|
} ),
|
|
|
|
new ProgressBarPlugin(
|
|
|
|
getProgressBarPluginConfig( 'WP directives' )
|
|
|
|
),
|
|
|
|
],
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(j|t)sx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: require.resolve( 'babel-loader' ),
|
|
|
|
options: {
|
|
|
|
cacheDirectory:
|
|
|
|
process.env.BABEL_CACHE_DIRECTORY || true,
|
|
|
|
babelrc: false,
|
|
|
|
configFile: false,
|
|
|
|
presets: [
|
2023-11-21 10:46:15 +00:00
|
|
|
'@babel/preset-typescript',
|
2023-01-26 11:39:25 +00:00
|
|
|
[
|
|
|
|
'@babel/preset-react',
|
|
|
|
{
|
|
|
|
runtime: 'automatic',
|
|
|
|
importSource: 'preact',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
2023-06-27 10:22:12 +00:00
|
|
|
// Required until Webpack is updated to ^5.0.0
|
2023-01-26 11:39:25 +00:00
|
|
|
plugins: [
|
|
|
|
'@babel/plugin-proposal-optional-chaining',
|
2023-07-26 09:58:17 +00:00
|
|
|
'@babel/plugin-proposal-class-properties',
|
2023-01-26 11:39:25 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-07-07 09:05:06 +00:00
|
|
|
module.exports = {
|
|
|
|
getCoreConfig,
|
|
|
|
getFrontConfig,
|
|
|
|
getMainConfig,
|
|
|
|
getPaymentsConfig,
|
2021-03-16 11:40:22 +00:00
|
|
|
getExtensionsConfig,
|
2023-07-31 07:03:10 +00:00
|
|
|
getSiteEditorConfig,
|
2020-07-22 12:05:56 +00:00
|
|
|
getStylingConfig,
|
2023-01-26 11:39:25 +00:00
|
|
|
getInteractivityAPIConfig,
|
2020-07-07 09:05:06 +00:00
|
|
|
};
|