2018-11-13 19:12:32 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const path = require( 'path' );
|
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
|
|
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
|
|
|
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' ] },
|
|
|
|
'@wordpress/editor': { this: [ 'wp', 'editor' ] },
|
|
|
|
'@wordpress/element': { this: [ 'wp', 'element' ] },
|
|
|
|
'@wordpress/i18n': { this: [ 'wp', 'i18n' ] },
|
|
|
|
};
|
|
|
|
|
2018-02-13 19:03:53 +00:00
|
|
|
/**
|
|
|
|
* Config for compiling Gutenberg blocks JS.
|
|
|
|
*/
|
|
|
|
var GutenbergBlocksConfig = {
|
2018-11-13 19:12:32 +00:00
|
|
|
mode: NODE_ENV,
|
2018-02-13 19:03:53 +00:00
|
|
|
entry: {
|
|
|
|
'products-block': './assets/js/products-block.jsx',
|
|
|
|
// 'next-block-name': './assets/js/gutenberg/some-other-block.jsx', <-- How to add more gutenblocks to this.
|
|
|
|
},
|
|
|
|
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:12:32 +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',
|
|
|
|
'sass-loader',
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2018-02-13 19:03:53 +00:00
|
|
|
},
|
2018-11-13 19:12:32 +00:00
|
|
|
plugins: [
|
|
|
|
new CleanWebpackPlugin( 'build', {} ),
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: '[name].css',
|
|
|
|
}),
|
|
|
|
]
|
2018-02-13 19:03:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = [ GutenbergBlocksConfig ];
|