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;
|
|
|
|
}
|
|
|
|
|
2018-02-13 19:03:53 +00:00
|
|
|
/**
|
|
|
|
* Config for compiling Gutenberg blocks JS.
|
|
|
|
*/
|
2018-11-13 19:21:04 +00:00
|
|
|
const GutenbergBlocksConfig = {
|
2018-11-13 19:12:32 +00:00
|
|
|
mode: NODE_ENV,
|
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-06-17 14:23:59 +00:00
|
|
|
frontend: [ './assets/js/blocks/product-categories/frontend.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',
|
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: {
|
2019-06-17 14:23:59 +00:00
|
|
|
packages: {
|
|
|
|
test: /[\\/]node_modules[\\/]@woocommerce/,
|
|
|
|
name: 'packages',
|
|
|
|
chunks: 'all',
|
|
|
|
enforce: true,
|
|
|
|
priority: 10, // Higher priority to ensure @woocommerce/* packages are caught here.
|
|
|
|
},
|
2019-01-14 20:33:17 +00:00
|
|
|
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-05-13 12:08:32 +00:00
|
|
|
loader: 'babel-loader?cacheDirectory',
|
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: [
|
2019-03-04 17:48:27 +00:00
|
|
|
new CleanWebpackPlugin(),
|
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-05-13 12:08:32 +00:00
|
|
|
performance: {
|
|
|
|
hints: false,
|
|
|
|
},
|
|
|
|
stats: {
|
|
|
|
all: false,
|
|
|
|
assets: true,
|
|
|
|
builtAt: true,
|
|
|
|
colors: true,
|
|
|
|
errors: true,
|
|
|
|
hash: true,
|
|
|
|
timings: true,
|
|
|
|
},
|
2018-02-13 19:03:53 +00:00
|
|
|
};
|
|
|
|
|
2018-11-13 19:21:04 +00:00
|
|
|
module.exports = [ GutenbergBlocksConfig ];
|