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' );
|
|
|
|
const CleanWebpackPlugin = require( 'clean-webpack-plugin' );
|
2018-11-13 19:12:32 +00:00
|
|
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
|
|
|
const externals = {
|
|
|
|
// We can add @woocommerce packages here when wc-admin merges into wc core,
|
|
|
|
// for now we need to fetch those from npm.
|
|
|
|
'@wordpress/api-fetch': { this: [ 'wp', 'apiFetch' ] },
|
|
|
|
'@wordpress/blocks': { this: [ 'wp', 'blocks' ] },
|
|
|
|
'@wordpress/components': { this: [ 'wp', 'components' ] },
|
|
|
|
'@wordpress/compose': { this: [ 'wp', 'compose' ] },
|
2018-11-27 17:13:16 +00:00
|
|
|
'@wordpress/data': { this: [ 'wp', 'data' ] },
|
2018-11-13 19:12:32 +00:00
|
|
|
'@wordpress/element': { this: [ 'wp', 'element' ] },
|
2018-11-27 17:13:16 +00:00
|
|
|
'@wordpress/editor': { this: [ 'wp', 'editor' ] },
|
2018-11-13 19:12:32 +00:00
|
|
|
'@wordpress/i18n': { this: [ 'wp', 'i18n' ] },
|
2018-11-27 17:13:16 +00:00
|
|
|
'@wordpress/url': { this: [ 'wp', 'url' ] },
|
|
|
|
lodash: 'lodash',
|
2018-11-13 19:12:32 +00:00
|
|
|
};
|
|
|
|
|
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-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',
|
|
|
|
'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-01-30 21:27:56 +00:00
|
|
|
'products-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-02-19 21:09:36 +00:00
|
|
|
// Global styles
|
2019-02-21 19:00:47 +00:00
|
|
|
styles: [ './assets/css/style.scss', './assets/css/editor.scss' ],
|
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',
|
2018-11-13 19:12:32 +00:00
|
|
|
libraryTarget: 'this',
|
2018-02-13 19:03:53 +00:00
|
|
|
},
|
2018-11-13 19:12:32 +00:00
|
|
|
externals,
|
2019-01-14 20:33:17 +00:00
|
|
|
optimization: {
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
commons: {
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
name: 'vendors',
|
|
|
|
chunks: 'all',
|
|
|
|
},
|
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/,
|
2018-11-13 19:21:04 +00:00
|
|
|
loader: 'babel-loader',
|
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/styles.js',
|
|
|
|
], 'build/vendors.js' ),
|
2018-11-13 19:21:04 +00:00
|
|
|
],
|
2018-02-13 19:03:53 +00:00
|
|
|
};
|
|
|
|
|
2018-11-13 19:21:04 +00:00
|
|
|
module.exports = [ GutenbergBlocksConfig ];
|