2019-04-09 00:39:11 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const path = require( 'path' );
|
|
|
|
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
|
|
|
|
const fs = require( 'fs' );
|
2020-02-14 02:23:21 +00:00
|
|
|
const woocommerceAdminConfig = require( path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../../../webpack.config.js'
|
|
|
|
) );
|
2019-05-06 04:39:10 +00:00
|
|
|
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
|
2019-04-09 00:39:11 +00:00
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
const extArg = process.argv.find( ( arg ) => arg.startsWith( '--ext=' ) );
|
2019-04-09 00:39:11 +00:00
|
|
|
|
|
|
|
if ( ! extArg ) {
|
|
|
|
throw new Error( 'Please provide an extension.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
const extension = extArg.slice( 6 );
|
|
|
|
const extensionPath = path.join( __dirname, `${ extension }/js/index.js` );
|
|
|
|
|
|
|
|
if ( ! fs.existsSync( extensionPath ) ) {
|
|
|
|
throw new Error( 'Extension example does not exist.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
const webpackConfig = {
|
|
|
|
mode: 'development',
|
|
|
|
entry: {
|
|
|
|
[ extension ]: extensionPath,
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
filename: '[name]/dist/index.js',
|
|
|
|
path: path.resolve( __dirname ),
|
2019-04-29 03:31:21 +00:00
|
|
|
libraryTarget: 'this',
|
2019-04-09 00:39:11 +00:00
|
|
|
},
|
2019-04-29 03:31:21 +00:00
|
|
|
externals: woocommerceAdminConfig.externals,
|
2019-04-09 00:39:11 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
parser: {
|
|
|
|
amd: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
loader: 'babel-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js?$/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
presets: [
|
2020-02-14 02:23:21 +00:00
|
|
|
[
|
|
|
|
'@babel/preset-env',
|
|
|
|
{ loose: true, modules: 'commonjs' },
|
|
|
|
],
|
2019-04-09 00:39:11 +00:00
|
|
|
],
|
|
|
|
plugins: [ 'transform-es2015-template-literals' ],
|
|
|
|
},
|
|
|
|
},
|
2020-02-14 02:23:21 +00:00
|
|
|
include: new RegExp(
|
|
|
|
'/node_modules/(' +
|
|
|
|
'|acorn-jsx' +
|
|
|
|
'|d3-array' +
|
|
|
|
'|debug' +
|
|
|
|
'|regexpu-core' +
|
|
|
|
'|unicode-match-property-ecmascript' +
|
|
|
|
'|unicode-match-property-value-ecmascript)/'
|
2020-01-03 17:03:20 +00:00
|
|
|
),
|
2019-04-09 00:39:11 +00:00
|
|
|
},
|
2019-05-06 04:39:10 +00:00
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
2020-02-14 02:23:21 +00:00
|
|
|
use: [ MiniCssExtractPlugin.loader, 'css-loader' ],
|
2019-05-06 04:39:10 +00:00
|
|
|
},
|
2019-04-09 00:39:11 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
extensions: [ '.json', '.js', '.jsx' ],
|
2020-02-14 02:23:21 +00:00
|
|
|
modules: [ 'node_modules' ],
|
2019-04-09 00:39:11 +00:00
|
|
|
alias: {
|
2020-02-14 02:23:21 +00:00
|
|
|
'gutenberg-components': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../../../node_modules/@wordpress/components/src'
|
|
|
|
),
|
2020-01-14 19:56:10 +00:00
|
|
|
'@woocommerce/wc-admin-settings': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../../../client/settings/index.js'
|
|
|
|
),
|
2019-04-09 00:39:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new CopyWebpackPlugin( [
|
|
|
|
{
|
|
|
|
from: path.join( __dirname, `${ extension }/` ),
|
|
|
|
to: path.resolve( __dirname, `../../../../${ extension }/` ),
|
|
|
|
},
|
|
|
|
] ),
|
2019-05-06 04:39:10 +00:00
|
|
|
new MiniCssExtractPlugin( {
|
|
|
|
filename: '[name]/dist/style.css',
|
|
|
|
} ),
|
2019-04-09 00:39:11 +00:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
webpackConfig.devtool = 'source-map';
|
|
|
|
|
|
|
|
module.exports = webpackConfig;
|