2018-11-13 19:12:32 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const path = require( 'path' );
|
2019-02-19 21:09:36 +00:00
|
|
|
const MergeExtractFilesPlugin = require( './bin/merge-extract-files-webpack-plugin' );
|
2018-11-13 19:21:04 +00:00
|
|
|
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
|
2019-05-30 14:17:00 +00:00
|
|
|
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
|
2019-05-21 10:29:09 +00:00
|
|
|
const ProgressBarPlugin = require( 'progress-bar-webpack-plugin' );
|
2019-06-12 15:50:57 +00:00
|
|
|
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
|
2019-05-21 10:29:09 +00:00
|
|
|
const chalk = require( 'chalk' );
|
2018-11-13 19:12:32 +00:00
|
|
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
2019-02-19 21:09:36 +00:00
|
|
|
function findModuleMatch( module, match ) {
|
|
|
|
if ( module.request && match.test( module.request ) ) {
|
|
|
|
return true;
|
|
|
|
} else if ( module.issuer ) {
|
|
|
|
return findModuleMatch( module.issuer, match );
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-22 09:39:00 +00:00
|
|
|
const baseConfig = {
|
|
|
|
mode: NODE_ENV,
|
|
|
|
performance: {
|
|
|
|
hints: false,
|
|
|
|
},
|
|
|
|
stats: {
|
|
|
|
all: false,
|
|
|
|
assets: true,
|
|
|
|
builtAt: true,
|
|
|
|
colors: true,
|
|
|
|
errors: true,
|
|
|
|
hash: true,
|
|
|
|
timings: true,
|
|
|
|
},
|
2019-08-13 14:43:48 +00:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'@woocommerce/settings': path.resolve( __dirname, 'assets/js/settings/index.js' ),
|
|
|
|
},
|
|
|
|
},
|
2019-07-22 09:39:00 +00:00
|
|
|
};
|
|
|
|
|
2018-02-13 19:03:53 +00:00
|
|
|
/**
|
|
|
|
* Config for compiling Gutenberg blocks JS.
|
|
|
|
*/
|
2018-11-13 19:21:04 +00:00
|
|
|
const GutenbergBlocksConfig = {
|
2019-07-22 09:39:00 +00:00
|
|
|
...baseConfig,
|
2018-02-13 19:03:53 +00:00
|
|
|
entry: {
|
2019-05-28 10:18:07 +00:00
|
|
|
// Shared blocks code
|
|
|
|
blocks: './assets/js/index.js',
|
2019-02-26 20:16:21 +00:00
|
|
|
// Blocks
|
2019-01-10 18:16:37 +00:00
|
|
|
'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',
|
2019-06-17 14:23:59 +00:00
|
|
|
'product-categories': './assets/js/blocks/product-categories/index.js',
|
2019-01-10 18:16:37 +00:00
|
|
|
'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',
|
2019-07-01 14:26:06 +00:00
|
|
|
'products-by-attribute': './assets/js/blocks/products-by-attribute/index.js',
|
2019-01-10 19:01:49 +00:00
|
|
|
'featured-product': './assets/js/blocks/featured-product/index.js',
|
2019-08-05 10:25:57 +00:00
|
|
|
'product-search': './assets/js/blocks/product-search/index.js',
|
2019-07-09 13:42:22 +00:00
|
|
|
'product-tag': './assets/js/blocks/product-tag/index.js',
|
2019-07-09 11:38:44 +00:00
|
|
|
'featured-category': './assets/js/blocks/featured-category/index.js',
|
2018-02-13 19:03:53 +00:00
|
|
|
},
|
|
|
|
output: {
|
2018-11-13 19:12:32 +00:00
|
|
|
path: path.resolve( __dirname, './build/' ),
|
2018-02-13 19:03:53 +00:00
|
|
|
filename: '[name].js',
|
2019-04-08 21:53:06 +00:00
|
|
|
library: [ 'wc', 'blocks', '[name]' ],
|
2018-11-13 19:12:32 +00:00
|
|
|
libraryTarget: 'this',
|
2019-04-08 21:53:06 +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',
|
2018-02-13 19:03:53 +00:00
|
|
|
},
|
2019-01-14 20:33:17 +00:00
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
commons: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
name: 'vendors',
|
|
|
|
chunks: 'all',
|
2019-05-21 10:29:09 +00:00
|
|
|
enforce: true,
|
2019-01-14 20:33:17 +00:00
|
|
|
},
|
2019-02-19 21:09:36 +00:00
|
|
|
editor: {
|
|
|
|
// Capture all `editor` stylesheets and the components stylesheets.
|
|
|
|
test: ( module = {} ) =>
|
|
|
|
module.constructor.name === 'CssModule' &&
|
|
|
|
( findModuleMatch( module, /editor\.scss$/ ) ||
|
|
|
|
findModuleMatch( module, /[\\/]components[\\/]/ ) ),
|
|
|
|
name: 'editor',
|
|
|
|
chunks: 'all',
|
|
|
|
enforce: true,
|
|
|
|
priority: 10,
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
test: /style\.scss$/,
|
|
|
|
name: 'style',
|
|
|
|
chunks: 'all',
|
|
|
|
enforce: true,
|
|
|
|
priority: 5,
|
|
|
|
},
|
2019-01-14 20:33:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-02-13 19:03:53 +00:00
|
|
|
module: {
|
2018-11-13 19:12:32 +00:00
|
|
|
rules: [
|
2018-02-13 19:03:53 +00:00
|
|
|
{
|
2018-11-13 19:12:32 +00:00
|
|
|
test: /\.jsx?$/,
|
2018-02-13 19:03:53 +00:00
|
|
|
exclude: /node_modules/,
|
2019-07-29 12:00:26 +00:00
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
2019-08-13 13:51:44 +00:00
|
|
|
presets: [ '@wordpress/babel-preset-default' ],
|
|
|
|
plugins: [
|
|
|
|
NODE_ENV === 'production' ? require.resolve( 'babel-plugin-transform-react-remove-prop-types' ) : false,
|
|
|
|
].filter( Boolean ),
|
2019-07-29 12:00:26 +00:00
|
|
|
},
|
|
|
|
},
|
2018-02-13 19:03:53 +00:00
|
|
|
},
|
2018-11-13 19:12:32 +00:00
|
|
|
{
|
|
|
|
test: /\.s[c|a]ss$/,
|
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
MiniCssExtractPlugin.loader,
|
2019-01-10 18:16:37 +00:00
|
|
|
{ loader: 'css-loader', options: { importLoaders: 1 } },
|
2018-11-13 19:12:32 +00:00
|
|
|
'postcss-loader',
|
2018-11-21 16:33:21 +00:00
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
query: {
|
|
|
|
includePaths: [ 'assets/css/abstracts' ],
|
|
|
|
data:
|
|
|
|
'@import "_colors"; ' +
|
2018-11-29 18:10:08 +00:00
|
|
|
'@import "_variables"; ' +
|
2018-11-21 16:33:21 +00:00
|
|
|
'@import "_breakpoints"; ' +
|
|
|
|
'@import "_mixins"; ',
|
|
|
|
},
|
2018-11-27 17:13:16 +00:00
|
|
|
},
|
2018-11-13 19:21:04 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2018-02-13 19:03:53 +00:00
|
|
|
},
|
2018-11-13 19:12:32 +00:00
|
|
|
plugins: [
|
2018-11-13 19:21:04 +00:00
|
|
|
new MiniCssExtractPlugin( {
|
2018-11-13 19:12:32 +00:00
|
|
|
filename: '[name].css',
|
2018-11-13 19:21:04 +00:00
|
|
|
} ),
|
2019-02-19 21:09:36 +00:00
|
|
|
new MergeExtractFilesPlugin( [
|
|
|
|
'build/editor.js',
|
|
|
|
'build/style.js',
|
|
|
|
], 'build/vendors.js' ),
|
2019-05-13 12:08:32 +00:00
|
|
|
new ProgressBarPlugin( {
|
|
|
|
format: chalk.blue( 'Build' ) + ' [:bar] ' + chalk.green( ':percent' ) + ' :msg (:elapsed seconds)',
|
|
|
|
} ),
|
2019-06-12 15:50:57 +00:00
|
|
|
new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ),
|
2018-11-13 19:21:04 +00:00
|
|
|
],
|
2019-07-22 09:39:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const BlocksFrontendConfig = {
|
|
|
|
...baseConfig,
|
|
|
|
entry: './assets/js/blocks/product-categories/frontend.js',
|
|
|
|
output: {
|
|
|
|
path: path.resolve( __dirname, './build/' ),
|
|
|
|
filename: 'frontend.js',
|
2019-05-13 12:08:32 +00:00
|
|
|
},
|
2019-07-22 09:39:00 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
exclude: /node_modules/,
|
2019-07-29 12:00:26 +00:00
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
2019-07-31 13:59:07 +00:00
|
|
|
presets: [
|
|
|
|
[ '@babel/preset-env', {
|
|
|
|
modules: false,
|
|
|
|
targets: {
|
|
|
|
browsers: [ 'extends @wordpress/browserslist-config' ],
|
|
|
|
},
|
|
|
|
} ],
|
2019-07-29 12:00:26 +00:00
|
|
|
],
|
2019-07-31 13:59:07 +00:00
|
|
|
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' ),
|
2019-08-13 13:51:44 +00:00
|
|
|
NODE_ENV === 'production' ? require.resolve( 'babel-plugin-transform-react-remove-prop-types' ) : false,
|
2019-07-31 13:59:07 +00:00
|
|
|
].filter( Boolean ),
|
2019-07-29 12:00:26 +00:00
|
|
|
},
|
|
|
|
},
|
2019-07-22 09:39:00 +00:00
|
|
|
},
|
|
|
|
],
|
2019-05-13 12:08:32 +00:00
|
|
|
},
|
2019-07-22 09:39:00 +00:00
|
|
|
plugins: [
|
|
|
|
new CleanWebpackPlugin(),
|
|
|
|
new ProgressBarPlugin( {
|
|
|
|
format: chalk.blue( 'Build frontend scripts' ) + ' [:bar] ' + chalk.green( ':percent' ) + ' :msg (:elapsed seconds)',
|
|
|
|
} ),
|
|
|
|
new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ),
|
|
|
|
],
|
2018-02-13 19:03:53 +00:00
|
|
|
};
|
|
|
|
|
2019-07-22 09:39:00 +00:00
|
|
|
module.exports = [ GutenbergBlocksConfig, BlocksFrontendConfig ];
|