2020-07-07 09:05:06 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const path = require( 'path' );
|
2021-06-29 11:18:29 +00:00
|
|
|
const { kebabCase } = require( 'lodash' );
|
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' );
|
|
|
|
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,
|
|
|
|
findModuleMatch,
|
2021-06-29 11:18:29 +00:00
|
|
|
getProgressBarPluginConfig,
|
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.
|
|
|
|
*/
|
2021-04-08 12:31:12 +00:00
|
|
|
const sharedPlugins = [
|
|
|
|
CHECK_CIRCULAR_DEPS === 'true'
|
|
|
|
? new CircularDependencyPlugin( {
|
|
|
|
exclude: /node_modules/,
|
|
|
|
cwd: process.cwd(),
|
|
|
|
failOnError: 'warn',
|
|
|
|
} )
|
|
|
|
: false,
|
2022-01-28 11:40:23 +00:00
|
|
|
// 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(),
|
2021-04-08 12:31:12 +00:00
|
|
|
new DependencyExtractionWebpackPlugin( {
|
|
|
|
injectPolyfill: true,
|
2022-02-02 14:56:16 +00:00
|
|
|
combineAssets: ASSET_CHECK,
|
|
|
|
outputFormat: ASSET_CHECK ? 'json' : 'php',
|
2021-04-08 12:31:12 +00:00
|
|
|
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 ) => {
|
|
|
|
return `${ kebabCase( chunkData.chunk.name ) }.js`;
|
|
|
|
},
|
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
|
|
|
library: [ 'wc', '[name]' ],
|
|
|
|
libraryTarget: 'this',
|
|
|
|
// This fixes an issue with multiple webpack projects using chunking
|
|
|
|
// overwriting each other's chunk loader function.
|
|
|
|
// See https://webpack.js.org/configuration/output/#outputjsonpfunction
|
|
|
|
jsonpFunction: 'webpackWcBlocksJsonp',
|
|
|
|
},
|
|
|
|
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: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
|
|
|
presets: [ '@wordpress/babel-preset-default' ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
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: [
|
2021-04-08 12:31:12 +00:00
|
|
|
...sharedPlugins,
|
2020-07-17 14:55:55 +00:00
|
|
|
new ProgressBarPlugin(
|
|
|
|
getProgressBarPluginConfig( 'Core', options.fileSuffix )
|
|
|
|
),
|
2020-07-07 09:05:06 +00:00
|
|
|
new CreateFileWebpack( {
|
|
|
|
path: './',
|
|
|
|
// 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,
|
2021-06-29 11:18:29 +00:00
|
|
|
splitChunks: {
|
|
|
|
automaticNameDelimiter: '--',
|
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin( {
|
|
|
|
cache: true,
|
|
|
|
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',
|
|
|
|
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',
|
|
|
|
// This fixes an issue with multiple webpack projects using chunking
|
|
|
|
// overwriting each other's chunk loader function.
|
|
|
|
// See https://webpack.js.org/configuration/output/#outputjsonpfunction
|
2021-11-09 15:10:47 +00:00
|
|
|
// This can be removed when moving to webpack 5:
|
|
|
|
// https://webpack.js.org/blog/2020-10-10-webpack-5-release/#automatic-unique-naming
|
2020-07-07 09:05:06 +00:00
|
|
|
jsonpFunction: 'webpackWcBlocksJsonp',
|
|
|
|
},
|
|
|
|
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: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
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,
|
|
|
|
].filter( Boolean ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
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: {
|
|
|
|
minSize: 0,
|
|
|
|
automaticNameDelimiter: '--',
|
|
|
|
cacheGroups: {
|
|
|
|
commons: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
name: 'wc-blocks-vendors',
|
|
|
|
chunks: 'all',
|
|
|
|
enforce: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin( {
|
|
|
|
cache: true,
|
|
|
|
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: [
|
2021-04-08 12:31:12 +00:00
|
|
|
...sharedPlugins,
|
2020-07-17 14:55:55 +00:00
|
|
|
new ProgressBarPlugin(
|
|
|
|
getProgressBarPluginConfig( 'Main', options.fileSuffix )
|
|
|
|
),
|
2022-02-01 16:42:15 +00:00
|
|
|
new CopyWebpackPlugin( {
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: './assets/js/blocks/checkout/block.json',
|
|
|
|
to: './checkout/block.json',
|
|
|
|
},
|
2022-04-28 15:31:59 +00:00
|
|
|
{
|
2022-05-19 16:16:46 +00:00
|
|
|
from:
|
|
|
|
'./assets/js/blocks/featured-items/featured-category/block.json',
|
2022-04-28 15:31:59 +00:00
|
|
|
to: './featured-category/block.json',
|
|
|
|
},
|
2022-04-28 15:04:56 +00:00
|
|
|
{
|
2022-05-19 16:16:46 +00:00
|
|
|
from:
|
|
|
|
'./assets/js/blocks/featured-items/featured-product/block.json',
|
2022-04-28 15:04:56 +00:00
|
|
|
to: './featured-product/block.json',
|
|
|
|
},
|
2022-05-13 12:57:34 +00:00
|
|
|
{
|
|
|
|
from:
|
|
|
|
'./assets/js/blocks/handpicked-products/block.json',
|
|
|
|
to: './handpicked-products/block.json',
|
|
|
|
},
|
2022-05-20 12:43:43 +00:00
|
|
|
{
|
|
|
|
from: './assets/js/blocks/product-tag/block.json',
|
|
|
|
to: './product-tag/block.json',
|
|
|
|
},
|
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',
|
|
|
|
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`,
|
|
|
|
// This fixes an issue with multiple webpack projects using chunking
|
|
|
|
// overwriting each other's chunk loader function.
|
|
|
|
// See https://webpack.js.org/configuration/output/#outputjsonpfunction
|
2021-11-09 15:10:47 +00:00
|
|
|
// This can be removed when moving to webpack 5:
|
|
|
|
// https://webpack.js.org/blog/2020-10-10-webpack-5-release/#automatic-unique-naming
|
2020-07-07 09:05:06 +00:00
|
|
|
jsonpFunction: 'webpackWcBlocksJsonp',
|
|
|
|
},
|
|
|
|
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: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
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,
|
|
|
|
].filter( Boolean ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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: '--',
|
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin( {
|
|
|
|
cache: true,
|
|
|
|
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: [
|
2021-04-08 12:31:12 +00:00
|
|
|
...sharedPlugins,
|
2020-07-17 14:55:55 +00:00
|
|
|
new ProgressBarPlugin(
|
|
|
|
getProgressBarPluginConfig( 'Frontend', options.fileSuffix )
|
|
|
|
),
|
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',
|
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
|
|
|
filename: `[name].js`,
|
|
|
|
// This fixes an issue with multiple webpack projects using chunking
|
|
|
|
// overwriting each other's chunk loader function.
|
|
|
|
// See https://webpack.js.org/configuration/output/#outputjsonpfunction
|
|
|
|
jsonpFunction: 'webpackWcBlocksPaymentMethodExtensionJsonp',
|
|
|
|
},
|
|
|
|
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: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
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,
|
|
|
|
].filter( Boolean ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
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: '--',
|
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin( {
|
|
|
|
cache: true,
|
|
|
|
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: [
|
2021-04-08 12:31:12 +00:00
|
|
|
...sharedPlugins,
|
2020-07-22 12:05:56 +00:00
|
|
|
new ProgressBarPlugin(
|
|
|
|
getProgressBarPluginConfig(
|
|
|
|
'Payment Method Extensions',
|
|
|
|
options.fileSuffix
|
|
|
|
)
|
|
|
|
),
|
|
|
|
],
|
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',
|
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
|
|
|
filename: `[name].js`,
|
|
|
|
jsonpFunction: 'webpackWcBlocksExtensionsMethodExtensionJsonp',
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(j|t)sx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
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,
|
|
|
|
].filter( Boolean ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
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: '--',
|
|
|
|
},
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin( {
|
|
|
|
cache: true,
|
|
|
|
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: [
|
2021-04-08 12:31:12 +00:00
|
|
|
...sharedPlugins,
|
2021-03-16 11:40:22 +00:00
|
|
|
new ProgressBarPlugin(
|
|
|
|
getProgressBarPluginConfig(
|
|
|
|
'Experimental Extensions',
|
|
|
|
options.fileSuffix
|
|
|
|
)
|
|
|
|
),
|
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
...resolve,
|
2021-06-29 11:18:29 +00:00
|
|
|
extensions: [ '.js', '.ts', '.tsx' ],
|
2021-03-16 11:40:22 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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 = {} ) => {
|
|
|
|
let { fileSuffix } = options;
|
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
fileSuffix = fileSuffix ? `-${ fileSuffix }` : '';
|
|
|
|
const resolve = alias
|
|
|
|
? {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
entry: getEntryConfig( 'styling', options.exclude || [] ),
|
|
|
|
output: {
|
|
|
|
devtoolNamespace: 'wc',
|
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
|
|
|
filename: `[name]-style${ fileSuffix }.js`,
|
|
|
|
library: [ 'wc', 'blocks', '[name]' ],
|
|
|
|
libraryTarget: 'this',
|
|
|
|
// This fixes an issue with multiple webpack projects using chunking
|
|
|
|
// overwriting each other's chunk loader function.
|
|
|
|
// See https://webpack.js.org/configuration/output/#outputjsonpfunction
|
|
|
|
jsonpFunction: 'webpackWcBlocksJsonp',
|
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
|
|
|
minSize: 0,
|
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.
|
2020-07-22 12:05:56 +00:00
|
|
|
test: ( module = {} ) =>
|
|
|
|
module.constructor.name === 'CssModule' &&
|
|
|
|
( findModuleMatch( module, /editor\.scss$/ ) ||
|
|
|
|
findModuleMatch(
|
|
|
|
module,
|
2020-09-02 08:21:46 +00:00
|
|
|
/[\\/]assets[\\/]js[\\/]editor-components[\\/]/
|
2020-07-22 12:05:56 +00:00
|
|
|
) ),
|
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,
|
|
|
|
},
|
2021-06-09 14:09:42 +00:00
|
|
|
vendorsStyle: {
|
2020-07-22 12:05:56 +00:00
|
|
|
test: /\/node_modules\/.*?style\.s?css$/,
|
2021-06-09 14:09:42 +00:00
|
|
|
name: 'wc-blocks-vendors-style',
|
2020-07-22 12:05:56 +00:00
|
|
|
chunks: 'all',
|
|
|
|
priority: 7,
|
|
|
|
},
|
2021-06-09 14:09:42 +00:00
|
|
|
blocksStyle: {
|
|
|
|
// Capture all stylesheets with name `style` or name that starts with underscore (abstracts).
|
2020-07-22 12:05:56 +00:00
|
|
|
test: /(style|_.*)\.scss$/,
|
2021-06-09 14:09:42 +00:00
|
|
|
name: 'wc-blocks-style',
|
2020-07-22 12:05:56 +00:00
|
|
|
chunks: 'all',
|
|
|
|
priority: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\/node_modules\/.*?style\.s?css$/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
{ loader: 'css-loader', options: { importLoaders: 1 } },
|
|
|
|
'postcss-loader',
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
2021-01-07 12:40:00 +00:00
|
|
|
options: {
|
|
|
|
sassOptions: {
|
|
|
|
includePaths: [ 'node_modules' ],
|
|
|
|
},
|
|
|
|
additionalData: ( content ) => {
|
|
|
|
const styleImports = [
|
|
|
|
'colors',
|
|
|
|
'breakpoints',
|
|
|
|
'variables',
|
|
|
|
'mixins',
|
|
|
|
'animations',
|
|
|
|
'z-index',
|
|
|
|
]
|
|
|
|
.map(
|
|
|
|
( imported ) =>
|
|
|
|
`@import "~@wordpress/base-styles/${ imported }";`
|
|
|
|
)
|
|
|
|
.join( ' ' );
|
|
|
|
return styleImports + content;
|
|
|
|
},
|
2020-07-22 12:05:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
{ loader: 'css-loader', options: { importLoaders: 1 } },
|
|
|
|
'postcss-loader',
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
2021-01-07 12:40:00 +00:00
|
|
|
options: {
|
|
|
|
sassOptions: {
|
|
|
|
includePaths: [ 'assets/css/abstracts' ],
|
|
|
|
},
|
|
|
|
additionalData: ( content, loaderContext ) => {
|
|
|
|
const {
|
|
|
|
resourcePath,
|
|
|
|
rootContext,
|
|
|
|
} = loaderContext;
|
|
|
|
const relativePath = path.relative(
|
|
|
|
rootContext,
|
|
|
|
resourcePath
|
|
|
|
);
|
|
|
|
|
|
|
|
if (
|
|
|
|
relativePath.startsWith(
|
|
|
|
'assets/css/abstracts/'
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
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: [
|
2020-07-22 12:05:56 +00:00
|
|
|
new ProgressBarPlugin(
|
|
|
|
getProgressBarPluginConfig( 'Styles', options.fileSuffix )
|
|
|
|
),
|
2020-07-07 09:05:06 +00:00
|
|
|
new WebpackRTLPlugin( {
|
2020-07-22 12:05:56 +00:00
|
|
|
filename: `[name]${ fileSuffix }-rtl.css`,
|
2020-07-07 09:05:06 +00:00
|
|
|
minify: {
|
|
|
|
safe: true,
|
|
|
|
},
|
|
|
|
} ),
|
|
|
|
new MiniCssExtractPlugin( {
|
2020-07-22 12:05:56 +00:00
|
|
|
filename: `[name]${ fileSuffix }.css`,
|
2020-07-07 09:05:06 +00:00
|
|
|
} ),
|
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,
|
|
|
|
extensions: [ '.js', '.ts', '.tsx' ],
|
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getCoreConfig,
|
|
|
|
getFrontConfig,
|
|
|
|
getMainConfig,
|
|
|
|
getPaymentsConfig,
|
2021-03-16 11:40:22 +00:00
|
|
|
getExtensionsConfig,
|
2020-07-22 12:05:56 +00:00
|
|
|
getStylingConfig,
|
2020-07-07 09:05:06 +00:00
|
|
|
};
|