2018-11-13 19:12:32 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const path = require( 'path' );
|
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
|
|
|
};
|
|
|
|
|
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: {
|
2018-11-19 16:31:43 +00:00
|
|
|
// Legacy block
|
|
|
|
'products-block': './assets/js/legacy/products-block.jsx',
|
2018-11-19 16:33:17 +00:00
|
|
|
// New blocks
|
|
|
|
'product-category-block': './assets/js/product-category-block.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',
|
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,
|
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,
|
|
|
|
'css-loader',
|
|
|
|
'postcss-loader',
|
2018-11-21 16:33:21 +00:00
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
query: {
|
|
|
|
includePaths: [ 'assets/css/abstracts' ],
|
|
|
|
data:
|
|
|
|
'@import "_colors"; ' +
|
|
|
|
'@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: [
|
|
|
|
new CleanWebpackPlugin( 'build', {} ),
|
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
|
|
|
} ),
|
|
|
|
],
|
2018-02-13 19:03:53 +00:00
|
|
|
};
|
|
|
|
|
2018-11-13 19:21:04 +00:00
|
|
|
module.exports = [ GutenbergBlocksConfig ];
|