2018-10-30 18:57:48 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-01-15 10:55:54 +00:00
|
|
|
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
|
2018-11-06 21:53:22 +00:00
|
|
|
const { get } = require( 'lodash' );
|
|
|
|
const path = require( 'path' );
|
2018-11-15 18:16:23 +00:00
|
|
|
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
|
2019-02-12 20:02:02 +00:00
|
|
|
const { DefinePlugin } = require( 'webpack' );
|
2019-03-14 10:18:54 +00:00
|
|
|
const WebpackRTLPlugin = require( 'webpack-rtl-plugin' );
|
2019-10-08 22:02:26 +00:00
|
|
|
const FixStyleOnlyEntriesPlugin = require( 'webpack-fix-style-only-entries' );
|
2018-11-06 21:53:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
const CustomTemplatedPathPlugin = require( '@wordpress/custom-templated-path-webpack-plugin' );
|
|
|
|
|
2018-07-23 20:14:40 +00:00
|
|
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
2018-04-17 21:38:56 +00:00
|
|
|
|
2019-11-17 22:39:27 +00:00
|
|
|
// generate-feature-config.php defaults to 'plugin', so lets match that here.
|
|
|
|
let WC_ADMIN_PHASE = process.env.WC_ADMIN_PHASE || 'plugin';
|
2019-02-12 20:02:02 +00:00
|
|
|
if ( [ 'development', 'plugin', 'core' ].indexOf( WC_ADMIN_PHASE ) === -1 ) {
|
2019-11-17 22:39:27 +00:00
|
|
|
WC_ADMIN_PHASE = 'plugin';
|
2019-02-12 20:02:02 +00:00
|
|
|
}
|
2020-02-14 02:23:21 +00:00
|
|
|
const WC_ADMIN_CONFIG = require( path.join(
|
|
|
|
__dirname,
|
|
|
|
'config',
|
|
|
|
WC_ADMIN_PHASE + '.json'
|
|
|
|
) );
|
|
|
|
const WC_ADMIN_ADDITIONAL_FEATURES =
|
|
|
|
( process.env.WC_ADMIN_ADDITIONAL_FEATURES &&
|
|
|
|
JSON.parse( process.env.WC_ADMIN_ADDITIONAL_FEATURES ) ) ||
|
|
|
|
{};
|
2019-02-12 20:02:02 +00:00
|
|
|
|
2018-04-17 21:38:56 +00:00
|
|
|
const externals = {
|
2018-08-21 19:02:49 +00:00
|
|
|
'@wordpress/api-fetch': { this: [ 'wp', 'apiFetch' ] },
|
2018-07-23 20:14:40 +00:00
|
|
|
'@wordpress/blocks': { this: [ 'wp', 'blocks' ] },
|
|
|
|
'@wordpress/data': { this: [ 'wp', 'data' ] },
|
|
|
|
'@wordpress/editor': { this: [ 'wp', 'editor' ] },
|
|
|
|
'@wordpress/element': { this: [ 'wp', 'element' ] },
|
|
|
|
'@wordpress/hooks': { this: [ 'wp', 'hooks' ] },
|
2019-07-17 01:35:43 +00:00
|
|
|
'@wordpress/url': { this: [ 'wp', 'url' ] },
|
2018-07-23 20:14:40 +00:00
|
|
|
'@wordpress/html-entities': { this: [ 'wp', 'htmlEntities' ] },
|
|
|
|
'@wordpress/i18n': { this: [ 'wp', 'i18n' ] },
|
|
|
|
'@wordpress/keycodes': { this: [ 'wp', 'keycodes' ] },
|
2019-09-23 21:47:08 +00:00
|
|
|
'@woocommerce/settings': { this: [ 'wc', 'wcSettings' ] },
|
2018-04-17 21:38:56 +00:00
|
|
|
tinymce: 'tinymce',
|
|
|
|
moment: 'moment',
|
2018-07-23 20:14:40 +00:00
|
|
|
react: 'React',
|
2019-04-12 02:52:03 +00:00
|
|
|
lodash: 'lodash',
|
2018-07-23 20:14:40 +00:00
|
|
|
'react-dom': 'ReactDOM',
|
2018-04-17 21:38:56 +00:00
|
|
|
};
|
|
|
|
|
2018-11-15 18:16:23 +00:00
|
|
|
const wcAdminPackages = [
|
|
|
|
'components',
|
|
|
|
'csv-export',
|
|
|
|
'currency',
|
|
|
|
'date',
|
|
|
|
'navigation',
|
2019-01-29 16:48:46 +00:00
|
|
|
'number',
|
2018-11-15 18:16:23 +00:00
|
|
|
];
|
2018-10-30 18:57:48 +00:00
|
|
|
|
2018-11-15 18:16:23 +00:00
|
|
|
const entryPoints = {};
|
2020-02-14 02:23:21 +00:00
|
|
|
wcAdminPackages.forEach( ( name ) => {
|
2018-10-30 18:57:48 +00:00
|
|
|
externals[ `@woocommerce/${ name }` ] = {
|
2020-02-14 02:23:21 +00:00
|
|
|
this: [
|
|
|
|
'wc',
|
|
|
|
name.replace( /-([a-z])/g, ( match, letter ) =>
|
|
|
|
letter.toUpperCase()
|
|
|
|
),
|
|
|
|
],
|
2018-10-30 18:57:48 +00:00
|
|
|
};
|
2018-11-15 18:16:23 +00:00
|
|
|
entryPoints[ name ] = `./packages/${ name }`;
|
2018-10-30 18:57:48 +00:00
|
|
|
} );
|
|
|
|
|
2019-10-21 18:13:25 +00:00
|
|
|
const wpAdminScripts = [
|
|
|
|
'onboarding-homepage-notice',
|
2019-11-12 01:17:36 +00:00
|
|
|
'onboarding-product-notice',
|
2019-12-10 19:28:19 +00:00
|
|
|
'onboarding-product-import-notice',
|
2019-11-07 00:17:46 +00:00
|
|
|
'onboarding-tax-notice',
|
2019-10-21 18:13:25 +00:00
|
|
|
];
|
2020-02-14 02:23:21 +00:00
|
|
|
wpAdminScripts.forEach( ( name ) => {
|
2019-10-21 18:13:25 +00:00
|
|
|
entryPoints[ name ] = `./client/wp-admin-scripts/${ name }`;
|
|
|
|
} );
|
|
|
|
|
2018-04-17 21:38:56 +00:00
|
|
|
const webpackConfig = {
|
|
|
|
mode: NODE_ENV,
|
2018-05-04 14:44:19 +00:00
|
|
|
entry: {
|
2018-10-30 18:57:48 +00:00
|
|
|
app: './client/index.js',
|
2019-10-08 22:02:26 +00:00
|
|
|
ie: './client/ie.scss',
|
2018-11-15 18:16:23 +00:00
|
|
|
...entryPoints,
|
2018-05-04 14:44:19 +00:00
|
|
|
},
|
2018-04-17 21:38:56 +00:00
|
|
|
output: {
|
2019-10-21 18:13:25 +00:00
|
|
|
filename: ( data ) => {
|
2020-02-14 02:23:21 +00:00
|
|
|
return wpAdminScripts.includes( data.chunk.name )
|
|
|
|
? './dist/wp-admin-scripts/[name].js'
|
|
|
|
: './dist/[name]/index.js';
|
2019-10-21 18:13:25 +00:00
|
|
|
},
|
2018-10-30 18:57:48 +00:00
|
|
|
path: __dirname,
|
2018-11-06 21:53:22 +00:00
|
|
|
library: [ 'wc', '[modulename]' ],
|
2018-04-17 21:38:56 +00:00
|
|
|
libraryTarget: 'this',
|
|
|
|
},
|
|
|
|
externals,
|
|
|
|
module: {
|
|
|
|
rules: [
|
2018-12-06 22:08:40 +00:00
|
|
|
{
|
|
|
|
parser: {
|
|
|
|
amd: false,
|
|
|
|
},
|
|
|
|
},
|
2018-04-17 21:38:56 +00:00
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
loader: 'babel-loader',
|
2018-07-23 20:14:40 +00:00
|
|
|
exclude: /node_modules/,
|
2018-04-17 21:38:56 +00:00
|
|
|
},
|
2018-12-26 02:46:32 +00:00
|
|
|
{
|
|
|
|
test: /\.js?$/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
presets: [
|
2020-02-14 02:23:21 +00:00
|
|
|
[
|
|
|
|
'@babel/preset-env',
|
|
|
|
{ loose: true, modules: 'commonjs' },
|
|
|
|
],
|
2018-12-26 02:46:32 +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)/'
|
2018-12-26 02:46:32 +00:00
|
|
|
),
|
|
|
|
},
|
2018-09-24 15:36:35 +00:00
|
|
|
{ test: /\.md$/, use: 'raw-loader' },
|
2019-05-28 14:05:55 +00:00
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/,
|
|
|
|
loader: 'url-loader',
|
|
|
|
},
|
2018-04-17 21:38:56 +00:00
|
|
|
{
|
2018-11-15 18:16:23 +00:00
|
|
|
test: /\.s?css$/,
|
2019-01-15 10:55:54 +00:00
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
'css-loader',
|
|
|
|
{
|
|
|
|
// postcss loader so we can use autoprefixer and theme Gutenberg components
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
config: {
|
|
|
|
path: 'postcss.config.js',
|
2018-07-30 14:05:22 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-15 10:55:54 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
query: {
|
|
|
|
includePaths: [ 'client/stylesheets/abstracts' ],
|
|
|
|
data:
|
2019-11-22 00:19:37 +00:00
|
|
|
'@import "node_modules/@wordpress/base-styles/_colors.scss"; ' +
|
|
|
|
'@import "node_modules/@wordpress/base-styles/_variables.scss"; ' +
|
|
|
|
'@import "node_modules/@wordpress/base-styles/_mixins.scss"; ' +
|
|
|
|
'@import "node_modules/@wordpress/base-styles/_breakpoints.scss"; ' +
|
|
|
|
'@import "node_modules/@wordpress/base-styles/_animations.scss"; ' +
|
|
|
|
'@import "node_modules/@wordpress/base-styles/_z-index.scss"; ' +
|
2019-01-15 10:55:54 +00:00
|
|
|
'@import "_colors"; ' +
|
|
|
|
'@import "_variables"; ' +
|
|
|
|
'@import "_breakpoints"; ' +
|
|
|
|
'@import "_mixins"; ',
|
2018-05-14 13:41:30 +00:00
|
|
|
},
|
2019-01-15 10:55:54 +00:00
|
|
|
},
|
|
|
|
],
|
2018-04-17 21:38:56 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2018-05-10 16:35:46 +00:00
|
|
|
resolve: {
|
|
|
|
extensions: [ '.json', '.js', '.jsx' ],
|
2020-02-14 02:23:21 +00:00
|
|
|
modules: [ path.join( __dirname, 'client' ), 'node_modules' ],
|
2018-07-20 03:40:15 +00:00
|
|
|
alias: {
|
2020-02-14 02:23:21 +00:00
|
|
|
'gutenberg-components': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'node_modules/@wordpress/components/src'
|
|
|
|
),
|
2019-07-24 15:37:37 +00:00
|
|
|
// @todo - remove once https://github.com/WordPress/gutenberg/pull/16196 is released.
|
|
|
|
'react-spring': 'react-spring/web.cjs',
|
2019-09-23 21:47:08 +00:00
|
|
|
'@woocommerce/wc-admin-settings': path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'client/settings/index.js'
|
|
|
|
),
|
2018-07-20 03:40:15 +00:00
|
|
|
},
|
2018-05-10 16:35:46 +00:00
|
|
|
},
|
2018-10-30 18:57:48 +00:00
|
|
|
plugins: [
|
2019-10-08 22:02:26 +00:00
|
|
|
new FixStyleOnlyEntriesPlugin(),
|
2019-02-12 20:02:02 +00:00
|
|
|
// Inject the current feature flags.
|
|
|
|
new DefinePlugin( {
|
2020-02-14 02:23:21 +00:00
|
|
|
'window.wcAdminFeatures': {
|
|
|
|
...WC_ADMIN_CONFIG.features,
|
|
|
|
...WC_ADMIN_ADDITIONAL_FEATURES,
|
|
|
|
},
|
2019-02-12 20:02:02 +00:00
|
|
|
} ),
|
2018-11-06 21:53:22 +00:00
|
|
|
new CustomTemplatedPathPlugin( {
|
|
|
|
modulename( outputPath, data ) {
|
|
|
|
const entryName = get( data, [ 'chunk', 'name' ] );
|
|
|
|
if ( entryName ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
return entryName.replace( /-([a-z])/g, ( match, letter ) =>
|
|
|
|
letter.toUpperCase()
|
|
|
|
);
|
2018-11-06 21:53:22 +00:00
|
|
|
}
|
|
|
|
return outputPath;
|
|
|
|
},
|
|
|
|
} ),
|
2019-03-14 10:18:54 +00:00
|
|
|
new WebpackRTLPlugin( {
|
2019-09-06 14:12:50 +00:00
|
|
|
filename: './dist/[name]/style-rtl.css',
|
2019-03-20 02:55:43 +00:00
|
|
|
minify: {
|
|
|
|
safe: true,
|
|
|
|
},
|
2019-03-14 10:18:54 +00:00
|
|
|
} ),
|
2019-01-15 10:55:54 +00:00
|
|
|
new MiniCssExtractPlugin( {
|
2018-10-30 18:57:48 +00:00
|
|
|
filename: './dist/[name]/style.css',
|
|
|
|
} ),
|
2018-11-15 18:16:23 +00:00
|
|
|
new CopyWebpackPlugin(
|
2020-02-14 02:23:21 +00:00
|
|
|
wcAdminPackages.map( ( packageName ) => ( {
|
2018-11-15 18:16:23 +00:00
|
|
|
from: `./packages/${ packageName }/build-style/*.css`,
|
|
|
|
to: `./dist/${ packageName }/`,
|
|
|
|
flatten: true,
|
2020-02-14 02:23:21 +00:00
|
|
|
transform: ( content ) => content,
|
2018-11-15 18:16:23 +00:00
|
|
|
} ) )
|
|
|
|
),
|
2018-10-30 18:57:48 +00:00
|
|
|
],
|
2018-04-17 21:38:56 +00:00
|
|
|
};
|
|
|
|
|
2018-04-17 23:51:48 +00:00
|
|
|
if ( webpackConfig.mode !== 'production' ) {
|
|
|
|
webpackConfig.devtool = process.env.SOURCEMAP || 'source-map';
|
|
|
|
}
|
|
|
|
|
2018-04-17 21:38:56 +00:00
|
|
|
module.exports = webpackConfig;
|