2019-10-06 12:36:15 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const path = require( 'path' );
|
|
|
|
const MergeExtractFilesPlugin = require( './merge-extract-files-webpack-plugin' );
|
|
|
|
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' );
|
|
|
|
const chalk = require( 'chalk' );
|
2019-10-28 13:53:09 +00:00
|
|
|
const { omit } = require( 'lodash' );
|
2020-01-31 20:04:37 +00:00
|
|
|
const { DefinePlugin } = require( 'webpack' );
|
2019-10-06 12:36:15 +00:00
|
|
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
|
|
|
function findModuleMatch( module, match ) {
|
|
|
|
if ( module.request && match.test( module.request ) ) {
|
|
|
|
return true;
|
|
|
|
} else if ( module.issuer ) {
|
|
|
|
return findModuleMatch( module.issuer, match );
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const requestToExternal = ( request ) => {
|
|
|
|
const wcDepMap = {
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/blocks-registry': [ 'wc', 'wcBlocksRegistry' ],
|
2019-10-06 12:36:15 +00:00
|
|
|
'@woocommerce/settings': [ 'wc', 'wcSettings' ],
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/block-data': [ 'wc', 'wcBlocksData' ],
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|
|
|
|
if ( wcDepMap[ request ] ) {
|
|
|
|
return wcDepMap[ request ];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const requestToHandle = ( request ) => {
|
|
|
|
const wcHandleMap = {
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/blocks-registry': 'wc-blocks-registry',
|
2019-10-06 12:36:15 +00:00
|
|
|
'@woocommerce/settings': 'wc-settings',
|
|
|
|
'@woocommerce/block-settings': 'wc-settings',
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/block-data': 'wc-blocks-data-store',
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|
|
|
|
if ( wcHandleMap[ request ] ) {
|
|
|
|
return wcHandleMap[ request ];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const getAlias = ( options = {} ) => {
|
|
|
|
let { pathPart } = options;
|
|
|
|
pathPart = pathPart ? `${ pathPart }/` : '';
|
|
|
|
return {
|
2020-01-31 18:20:33 +00:00
|
|
|
'@woocommerce/atomic-components': path.resolve(
|
2019-10-06 12:36:15 +00:00
|
|
|
__dirname,
|
2020-01-31 18:20:33 +00:00
|
|
|
`../assets/js/${ pathPart }atomic/components/`
|
2019-10-06 12:36:15 +00:00
|
|
|
),
|
|
|
|
'@woocommerce/base-components': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/components/`
|
|
|
|
),
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/base-context': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/context/`
|
|
|
|
),
|
2019-10-06 12:36:15 +00:00
|
|
|
'@woocommerce/base-hocs': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/hocs/`
|
|
|
|
),
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/base-hooks': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/hooks/`
|
|
|
|
),
|
2019-11-15 14:41:23 +00:00
|
|
|
'@woocommerce/base-utils': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }base/utils/`
|
|
|
|
),
|
2019-10-06 12:36:15 +00:00
|
|
|
'@woocommerce/block-components': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }components/`
|
|
|
|
),
|
|
|
|
'@woocommerce/block-hocs': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }hocs`
|
|
|
|
),
|
2020-01-31 18:20:33 +00:00
|
|
|
'@woocommerce/blocks-registry': path.resolve(
|
2019-10-28 13:53:09 +00:00
|
|
|
__dirname,
|
2020-01-31 18:20:33 +00:00
|
|
|
'../assets/js/blocks-registry'
|
|
|
|
),
|
|
|
|
'@woocommerce/block-settings': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../assets/js/settings/blocks'
|
2019-10-28 13:53:09 +00:00
|
|
|
),
|
2020-01-31 18:20:33 +00:00
|
|
|
'@woocommerce/icons': path.resolve( __dirname, `../assets/js/icons` ),
|
2019-10-28 13:53:09 +00:00
|
|
|
'@woocommerce/resource-previews': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
`../assets/js/${ pathPart }previews/`
|
|
|
|
),
|
2020-02-11 16:13:20 +00:00
|
|
|
'@woocommerce/e2e-tests': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'node_modules/woocommerce/tests/e2e-tests'
|
|
|
|
),
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-01-31 20:04:37 +00:00
|
|
|
const stableMainEntry = {
|
2019-10-28 13:53:09 +00:00
|
|
|
// Shared blocks code
|
|
|
|
blocks: './assets/js/index.js',
|
2019-12-03 13:57:56 +00:00
|
|
|
|
2020-03-13 15:49:33 +00:00
|
|
|
// @wordpress/components styles
|
2020-03-27 20:56:48 +00:00
|
|
|
'panel-style': './node_modules/wordpress-components/src/panel/style.scss',
|
2020-03-13 15:49:33 +00:00
|
|
|
'custom-select-control-style':
|
2020-03-27 20:56:48 +00:00
|
|
|
'./node_modules/wordpress-components/src/custom-select-control/style.scss',
|
2020-03-13 15:49:33 +00:00
|
|
|
'checkbox-control-style':
|
2020-03-27 20:56:48 +00:00
|
|
|
'./node_modules/wordpress-components/src/checkbox-control/style.scss',
|
2020-03-13 15:49:33 +00:00
|
|
|
'spinner-style':
|
2020-03-27 20:56:48 +00:00
|
|
|
'./node_modules/wordpress-components/src/spinner/style.scss',
|
2020-03-16 20:57:12 +00:00
|
|
|
'snackbar-notice-style':
|
2020-03-27 20:56:48 +00:00
|
|
|
'./node_modules/wordpress-components/src/snackbar/style.scss',
|
2020-03-13 15:49:33 +00:00
|
|
|
|
2020-03-31 10:46:38 +00:00
|
|
|
// Styles for grid blocks. WP <=5.2 doesn't have the All Products block,
|
|
|
|
// so this file would not be included if not explicitly declared here.
|
|
|
|
// This file is excluded from the default build so CSS styles are included
|
|
|
|
// in the other the components are imported.
|
|
|
|
'product-list-style': './assets/js/base/components/product-list/style.scss',
|
|
|
|
|
2019-10-28 13:53:09 +00:00
|
|
|
// Blocks
|
|
|
|
'handpicked-products': './assets/js/blocks/handpicked-products/index.js',
|
|
|
|
'product-best-sellers': './assets/js/blocks/product-best-sellers/index.js',
|
|
|
|
'product-category': './assets/js/blocks/product-category/index.js',
|
|
|
|
'product-categories': './assets/js/blocks/product-categories/index.js',
|
|
|
|
'product-new': './assets/js/blocks/product-new/index.js',
|
|
|
|
'product-on-sale': './assets/js/blocks/product-on-sale/index.js',
|
|
|
|
'product-top-rated': './assets/js/blocks/product-top-rated/index.js',
|
|
|
|
'products-by-attribute':
|
|
|
|
'./assets/js/blocks/products-by-attribute/index.js',
|
|
|
|
'featured-product': './assets/js/blocks/featured-product/index.js',
|
|
|
|
'all-reviews': './assets/js/blocks/reviews/all-reviews/index.js',
|
|
|
|
'reviews-by-product':
|
|
|
|
'./assets/js/blocks/reviews/reviews-by-product/index.js',
|
|
|
|
'reviews-by-category':
|
|
|
|
'./assets/js/blocks/reviews/reviews-by-category/index.js',
|
|
|
|
'product-search': './assets/js/blocks/product-search/index.js',
|
|
|
|
'product-tag': './assets/js/blocks/product-tag/index.js',
|
|
|
|
'featured-category': './assets/js/blocks/featured-category/index.js',
|
|
|
|
'all-products': './assets/js/blocks/products/all-products/index.js',
|
2019-11-01 13:56:14 +00:00
|
|
|
'price-filter': './assets/js/blocks/price-filter/index.js',
|
2019-11-11 10:32:56 +00:00
|
|
|
'attribute-filter': './assets/js/blocks/attribute-filter/index.js',
|
2019-11-15 14:41:23 +00:00
|
|
|
'active-filters': './assets/js/blocks/active-filters/index.js',
|
2019-11-21 08:08:47 +00:00
|
|
|
'block-error-boundary':
|
|
|
|
'./assets/js/base/components/block-error-boundary/style.scss',
|
2020-01-31 20:04:37 +00:00
|
|
|
};
|
2019-12-03 13:57:56 +00:00
|
|
|
|
2020-01-31 20:04:37 +00:00
|
|
|
const experimentalMainEntry = {
|
2019-12-09 20:50:49 +00:00
|
|
|
cart: './assets/js/blocks/cart-checkout/cart/index.js',
|
|
|
|
checkout: './assets/js/blocks/cart-checkout/checkout/index.js',
|
2019-10-28 13:53:09 +00:00
|
|
|
};
|
|
|
|
|
2020-01-31 20:04:37 +00:00
|
|
|
const mainEntry =
|
2020-02-05 18:40:10 +00:00
|
|
|
process.env.WOOCOMMERCE_BLOCKS_PHASE === 'stable'
|
|
|
|
? stableMainEntry
|
|
|
|
: { ...stableMainEntry, ...experimentalMainEntry };
|
2020-01-31 20:04:37 +00:00
|
|
|
|
|
|
|
const stableFrontEndEntry = {
|
2019-10-28 13:53:09 +00:00
|
|
|
reviews: './assets/js/blocks/reviews/frontend.js',
|
|
|
|
'all-products': './assets/js/blocks/products/all-products/frontend.js',
|
2019-11-01 13:56:14 +00:00
|
|
|
'price-filter': './assets/js/blocks/price-filter/frontend.js',
|
2019-11-11 10:32:56 +00:00
|
|
|
'attribute-filter': './assets/js/blocks/attribute-filter/frontend.js',
|
2019-11-15 14:41:23 +00:00
|
|
|
'active-filters': './assets/js/blocks/active-filters/frontend.js',
|
2020-01-31 20:04:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const experimentalFrontEndEntry = {
|
2019-12-09 20:50:49 +00:00
|
|
|
checkout: './assets/js/blocks/cart-checkout/checkout/frontend.js',
|
|
|
|
cart: './assets/js/blocks/cart-checkout/cart/frontend.js',
|
2019-10-28 13:53:09 +00:00
|
|
|
};
|
|
|
|
|
2020-01-31 20:04:37 +00:00
|
|
|
const frontEndEntry =
|
2020-02-05 18:40:10 +00:00
|
|
|
process.env.WOOCOMMERCE_BLOCKS_PHASE === 'stable'
|
|
|
|
? stableFrontEndEntry
|
|
|
|
: { ...stableFrontEndEntry, ...experimentalFrontEndEntry };
|
2020-01-31 20:04:37 +00:00
|
|
|
|
2019-10-28 13:53:09 +00:00
|
|
|
const getEntryConfig = ( main = true, exclude = [] ) => {
|
|
|
|
const entryConfig = main ? mainEntry : frontEndEntry;
|
|
|
|
return omit( entryConfig, exclude );
|
|
|
|
};
|
|
|
|
|
2019-10-06 12:36:15 +00:00
|
|
|
const getMainConfig = ( options = {} ) => {
|
|
|
|
let { fileSuffix } = options;
|
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
fileSuffix = fileSuffix ? `-${ fileSuffix }` : '';
|
|
|
|
const resolve = alias
|
|
|
|
? {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
};
|
|
|
|
return {
|
2019-10-28 13:53:09 +00:00
|
|
|
entry: getEntryConfig( true, options.exclude || [] ),
|
2019-10-06 12:36:15 +00:00
|
|
|
output: {
|
2019-11-28 12:55:59 +00:00
|
|
|
devtoolNamespace: 'wc',
|
2019-10-06 12:36:15 +00:00
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
|
|
|
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
|
|
|
|
jsonpFunction: 'webpackWcBlocksJsonp',
|
|
|
|
},
|
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
2020-01-10 14:37:27 +00:00
|
|
|
minSize: 0,
|
2019-10-06 12:36:15 +00:00
|
|
|
cacheGroups: {
|
|
|
|
commons: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
name: 'vendors',
|
|
|
|
chunks: 'all',
|
|
|
|
enforce: true,
|
|
|
|
},
|
|
|
|
editor: {
|
|
|
|
// Capture all `editor` stylesheets and the components stylesheets.
|
|
|
|
test: ( module = {} ) =>
|
|
|
|
module.constructor.name === 'CssModule' &&
|
|
|
|
( findModuleMatch( module, /editor\.scss$/ ) ||
|
|
|
|
findModuleMatch(
|
|
|
|
module,
|
|
|
|
/[\\/]assets[\\/]components[\\/]/
|
|
|
|
) ),
|
|
|
|
name: 'editor',
|
|
|
|
chunks: 'all',
|
|
|
|
priority: 10,
|
|
|
|
},
|
2020-01-10 14:37:27 +00:00
|
|
|
'vendors-style': {
|
|
|
|
test: /\/node_modules\/.*?style\.s?css$/,
|
|
|
|
name: 'vendors-style',
|
|
|
|
chunks: 'all',
|
|
|
|
priority: 7,
|
|
|
|
},
|
2019-10-06 12:36:15 +00:00
|
|
|
style: {
|
|
|
|
test: /style\.scss$/,
|
|
|
|
name: 'style',
|
|
|
|
chunks: 'all',
|
|
|
|
priority: 5,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
|
|
|
presets: [ '@wordpress/babel-preset-default' ],
|
|
|
|
plugins: [
|
|
|
|
NODE_ENV === 'production'
|
|
|
|
? require.resolve(
|
|
|
|
'babel-plugin-transform-react-remove-prop-types'
|
|
|
|
)
|
|
|
|
: false,
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-proposal-class-properties'
|
|
|
|
),
|
|
|
|
].filter( Boolean ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-01-10 14:37:27 +00:00
|
|
|
test: /\/node_modules\/.*?style\.s?css$/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
{ loader: 'css-loader', options: { importLoaders: 1 } },
|
|
|
|
'postcss-loader',
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
query: {
|
|
|
|
includePaths: [ 'node_modules' ],
|
2020-03-16 20:57:12 +00:00
|
|
|
data: [
|
|
|
|
'colors',
|
|
|
|
'breakpoints',
|
|
|
|
'variables',
|
|
|
|
'mixins',
|
|
|
|
'animations',
|
|
|
|
'z-index',
|
|
|
|
]
|
|
|
|
.map(
|
|
|
|
( imported ) =>
|
|
|
|
`@import "~@wordpress/base-styles/${ imported }";`
|
|
|
|
)
|
|
|
|
.join( ' ' ),
|
2020-01-10 14:37:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
exclude: /node_modules/,
|
2019-10-06 12:36:15 +00:00
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
{ loader: 'css-loader', options: { importLoaders: 1 } },
|
|
|
|
'postcss-loader',
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
query: {
|
2020-03-16 20:57:12 +00:00
|
|
|
includePaths: [
|
|
|
|
'assets/css/abstracts',
|
|
|
|
'node_modules',
|
|
|
|
],
|
|
|
|
data: [
|
|
|
|
'_colors',
|
|
|
|
'_variables',
|
|
|
|
'_breakpoints',
|
|
|
|
'_mixins',
|
|
|
|
]
|
|
|
|
.map(
|
|
|
|
( imported ) =>
|
|
|
|
`@import "${ imported }";`
|
|
|
|
)
|
|
|
|
.join( ' ' ),
|
2019-10-06 12:36:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new WebpackRTLPlugin( {
|
|
|
|
filename: `[name]${ fileSuffix }-rtl.css`,
|
|
|
|
minify: {
|
|
|
|
safe: true,
|
|
|
|
},
|
|
|
|
} ),
|
|
|
|
new MiniCssExtractPlugin( {
|
|
|
|
filename: `[name]${ fileSuffix }.css`,
|
|
|
|
} ),
|
|
|
|
new MergeExtractFilesPlugin(
|
2019-10-28 13:53:09 +00:00
|
|
|
[
|
|
|
|
`build/editor${ fileSuffix }.js`,
|
|
|
|
`build/style${ fileSuffix }.js`,
|
|
|
|
],
|
|
|
|
`build/vendors${ fileSuffix }.js`
|
2019-10-06 12:36:15 +00:00
|
|
|
),
|
|
|
|
new ProgressBarPlugin( {
|
|
|
|
format:
|
|
|
|
chalk.blue( 'Build' ) +
|
|
|
|
' [:bar] ' +
|
|
|
|
chalk.green( ':percent' ) +
|
|
|
|
' :msg (:elapsed seconds)',
|
|
|
|
} ),
|
|
|
|
new DependencyExtractionWebpackPlugin( {
|
|
|
|
injectPolyfill: true,
|
|
|
|
requestToExternal,
|
|
|
|
requestToHandle,
|
|
|
|
} ),
|
2020-01-31 20:04:37 +00:00
|
|
|
new DefinePlugin( {
|
|
|
|
// Inject the `WOOCOMMERCE_BLOCKS_PHASE` global, used for feature flagging.
|
|
|
|
'process.env.WOOCOMMERCE_BLOCKS_PHASE': JSON.stringify(
|
2020-02-13 13:16:16 +00:00
|
|
|
// eslint-disable-next-line woocommerce/feature-flag
|
2020-01-31 20:04:37 +00:00
|
|
|
process.env.WOOCOMMERCE_BLOCKS_PHASE || 'experimental'
|
|
|
|
),
|
|
|
|
} ),
|
2019-10-06 12:36:15 +00:00
|
|
|
],
|
|
|
|
resolve,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const getFrontConfig = ( options = {} ) => {
|
|
|
|
let { fileSuffix } = options;
|
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
fileSuffix = fileSuffix ? `-${ fileSuffix }` : '';
|
|
|
|
const resolve = alias
|
|
|
|
? {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
};
|
|
|
|
return {
|
2019-10-28 13:53:09 +00:00
|
|
|
entry: getEntryConfig( false, options.exclude || [] ),
|
2019-10-06 12:36:15 +00:00
|
|
|
output: {
|
2019-11-28 12:55:59 +00:00
|
|
|
devtoolNamespace: 'wc',
|
2019-10-06 12:36:15 +00:00
|
|
|
path: path.resolve( __dirname, '../build/' ),
|
2019-11-12 12:13:59 +00:00
|
|
|
filename: `[name]-frontend${ fileSuffix }.js`,
|
2019-10-06 12:36:15 +00:00
|
|
|
// 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: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
'@babel/preset-env',
|
|
|
|
{
|
|
|
|
modules: false,
|
|
|
|
targets: {
|
|
|
|
browsers: [
|
|
|
|
'extends @wordpress/browserslist-config',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-proposal-object-rest-spread'
|
|
|
|
),
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-transform-react-jsx'
|
|
|
|
),
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-proposal-async-generator-functions'
|
|
|
|
),
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-transform-runtime'
|
|
|
|
),
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-proposal-class-properties'
|
|
|
|
),
|
|
|
|
NODE_ENV === 'production'
|
|
|
|
? require.resolve(
|
|
|
|
'babel-plugin-transform-react-remove-prop-types'
|
|
|
|
)
|
|
|
|
: false,
|
|
|
|
].filter( Boolean ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s[c|a]ss$/,
|
|
|
|
use: {
|
|
|
|
loader: 'ignore-loader',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new ProgressBarPlugin( {
|
|
|
|
format:
|
|
|
|
chalk.blue( 'Build frontend scripts' ) +
|
|
|
|
' [:bar] ' +
|
|
|
|
chalk.green( ':percent' ) +
|
|
|
|
' :msg (:elapsed seconds)',
|
|
|
|
} ),
|
|
|
|
new DependencyExtractionWebpackPlugin( {
|
|
|
|
injectPolyfill: true,
|
|
|
|
requestToExternal,
|
|
|
|
requestToHandle,
|
|
|
|
} ),
|
2020-01-31 20:04:37 +00:00
|
|
|
new DefinePlugin( {
|
|
|
|
// Inject the `WOOCOMMERCE_BLOCKS_PHASE` global, used for feature flagging.
|
|
|
|
'process.env.WOOCOMMERCE_BLOCKS_PHASE': JSON.stringify(
|
2020-02-13 13:16:16 +00:00
|
|
|
// eslint-disable-next-line woocommerce/feature-flag
|
2020-01-31 20:04:37 +00:00
|
|
|
process.env.WOOCOMMERCE_BLOCKS_PHASE || 'experimental'
|
|
|
|
),
|
|
|
|
} ),
|
2019-10-06 12:36:15 +00:00
|
|
|
],
|
|
|
|
resolve,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-03-30 12:07:49 +00:00
|
|
|
const getPaymentMethodsExtensionConfig = ( options = {} ) => {
|
|
|
|
const { alias, resolvePlugins = [] } = options;
|
|
|
|
const resolve = alias
|
|
|
|
? {
|
|
|
|
alias,
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
plugins: resolvePlugins,
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
entry: {
|
|
|
|
'wc-payment-method-extensions':
|
|
|
|
'./assets/js/payment-method-extensions/index.js',
|
|
|
|
},
|
|
|
|
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: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
'@babel/preset-env',
|
|
|
|
{
|
|
|
|
modules: false,
|
|
|
|
targets: {
|
|
|
|
browsers: [
|
|
|
|
'extends @wordpress/browserslist-config',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-proposal-object-rest-spread'
|
|
|
|
),
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-transform-react-jsx'
|
|
|
|
),
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-proposal-async-generator-functions'
|
|
|
|
),
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-transform-runtime'
|
|
|
|
),
|
|
|
|
require.resolve(
|
|
|
|
'@babel/plugin-proposal-class-properties'
|
|
|
|
),
|
|
|
|
NODE_ENV === 'production'
|
|
|
|
? require.resolve(
|
|
|
|
'babel-plugin-transform-react-remove-prop-types'
|
|
|
|
)
|
|
|
|
: false,
|
|
|
|
].filter( Boolean ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
{ loader: 'css-loader', options: { importLoaders: 1 } },
|
|
|
|
'postcss-loader',
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
query: {
|
|
|
|
includePaths: [
|
|
|
|
'assets/css/abstracts',
|
|
|
|
'node_modules',
|
|
|
|
],
|
|
|
|
data: [
|
|
|
|
'_colors',
|
|
|
|
'_variables',
|
|
|
|
'_breakpoints',
|
|
|
|
'_mixins',
|
|
|
|
]
|
|
|
|
.map(
|
|
|
|
( imported ) =>
|
|
|
|
`@import "${ imported }";`
|
|
|
|
)
|
|
|
|
.join( ' ' ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new WebpackRTLPlugin( {
|
|
|
|
filename: `[name]-rtl.css`,
|
|
|
|
minify: {
|
|
|
|
safe: true,
|
|
|
|
},
|
|
|
|
} ),
|
|
|
|
new MiniCssExtractPlugin( {
|
|
|
|
filename: `[name].css`,
|
|
|
|
} ),
|
|
|
|
new ProgressBarPlugin( {
|
|
|
|
format:
|
|
|
|
chalk.blue( 'Build payment method extension scripts' ) +
|
|
|
|
' [:bar] ' +
|
|
|
|
chalk.green( ':percent' ) +
|
|
|
|
' :msg (:elapsed seconds)',
|
|
|
|
} ),
|
|
|
|
new DependencyExtractionWebpackPlugin( {
|
|
|
|
injectPolyfill: true,
|
|
|
|
requestToExternal,
|
|
|
|
requestToHandle,
|
|
|
|
} ),
|
|
|
|
new DefinePlugin( {
|
|
|
|
// Inject the `WOOCOMMERCE_BLOCKS_PHASE` global, used for feature flagging.
|
|
|
|
'process.env.WOOCOMMERCE_BLOCKS_PHASE': JSON.stringify(
|
|
|
|
// eslint-disable-next-line woocommerce/feature-flag
|
|
|
|
process.env.WOOCOMMERCE_BLOCKS_PHASE || 'experimental'
|
|
|
|
),
|
|
|
|
} ),
|
|
|
|
],
|
|
|
|
resolve,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-10-06 12:36:15 +00:00
|
|
|
module.exports = {
|
|
|
|
getAlias,
|
|
|
|
getFrontConfig,
|
|
|
|
getMainConfig,
|
2020-03-30 12:07:49 +00:00
|
|
|
getPaymentMethodsExtensionConfig,
|
2019-10-06 12:36:15 +00:00
|
|
|
};
|