2018-11-13 19:12:32 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const path = require( 'path' );
|
2019-09-23 18:07:13 +00:00
|
|
|
const { kebabCase } = require( 'lodash' );
|
2019-05-30 14:17:00 +00:00
|
|
|
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
|
2019-05-21 10:29:09 +00:00
|
|
|
const ProgressBarPlugin = require( 'progress-bar-webpack-plugin' );
|
2019-06-12 15:50:57 +00:00
|
|
|
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
|
2019-05-21 10:29:09 +00:00
|
|
|
const chalk = require( 'chalk' );
|
2018-11-13 19:12:32 +00:00
|
|
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
2019-10-06 12:36:15 +00:00
|
|
|
const FallbackModuleDirectoryPlugin = require( './bin/fallback-module-directory-webpack-plugin' );
|
|
|
|
const {
|
|
|
|
getAlias,
|
|
|
|
getMainConfig,
|
|
|
|
getFrontConfig,
|
|
|
|
} = require( './bin/webpack-helpers.js' );
|
2019-02-19 21:09:36 +00:00
|
|
|
|
2019-07-22 09:39:00 +00:00
|
|
|
const baseConfig = {
|
|
|
|
mode: NODE_ENV,
|
|
|
|
performance: {
|
|
|
|
hints: false,
|
|
|
|
},
|
|
|
|
stats: {
|
|
|
|
all: false,
|
|
|
|
assets: true,
|
|
|
|
builtAt: true,
|
|
|
|
colors: true,
|
|
|
|
errors: true,
|
|
|
|
hash: true,
|
|
|
|
timings: true,
|
|
|
|
},
|
2019-10-28 11:00:04 +00:00
|
|
|
watchOptions: {
|
|
|
|
ignored: /node_modules/,
|
|
|
|
},
|
2019-08-22 20:56:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const CoreConfig = {
|
|
|
|
...baseConfig,
|
|
|
|
entry: {
|
2019-10-28 13:53:09 +00:00
|
|
|
wcBlocksRegistry: './assets/js/blocks-registry/index.js',
|
2019-09-23 18:07:13 +00:00
|
|
|
wcSettings: './assets/js/settings/shared/index.js',
|
2019-10-28 13:53:09 +00:00
|
|
|
wcBlocksData: './assets/js/data/index.js',
|
2019-08-13 14:43:48 +00:00
|
|
|
},
|
2019-08-22 20:56:47 +00:00
|
|
|
output: {
|
2019-09-23 18:07:13 +00:00
|
|
|
filename: ( chunkData ) => {
|
|
|
|
return `${ kebabCase( chunkData.chunk.name ) }.js`;
|
|
|
|
},
|
2019-08-22 20:56:47 +00:00
|
|
|
path: path.resolve( __dirname, './build/' ),
|
2019-08-27 15:25:32 +00:00
|
|
|
library: [ 'wc', '[name]' ],
|
2019-08-22 20:56:47 +00:00
|
|
|
libraryTarget: 'this',
|
|
|
|
// This fixes an issue with multiple webpack projects using chunking
|
|
|
|
// overwriting each other's chunk loader function.
|
|
|
|
// See https://webpack.js.org/configuration/output/#outputjsonpfunction
|
|
|
|
jsonpFunction: 'webpackWcBlocksJsonp',
|
|
|
|
},
|
2019-08-23 16:07:39 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader?cacheDirectory',
|
|
|
|
options: {
|
|
|
|
presets: [ '@wordpress/babel-preset-default' ],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-08-22 20:56:47 +00:00
|
|
|
plugins: [
|
|
|
|
new CleanWebpackPlugin(),
|
|
|
|
new ProgressBarPlugin( {
|
2019-09-05 15:09:31 +00:00
|
|
|
format:
|
|
|
|
chalk.blue( 'Build core script' ) +
|
|
|
|
' [:bar] ' +
|
|
|
|
chalk.green( ':percent' ) +
|
|
|
|
' :msg (:elapsed seconds)',
|
2019-08-22 20:56:47 +00:00
|
|
|
} ),
|
|
|
|
new DependencyExtractionWebpackPlugin( { injectPolyfill: true } ),
|
|
|
|
],
|
2019-07-22 09:39:00 +00:00
|
|
|
};
|
|
|
|
|
2018-11-13 19:21:04 +00:00
|
|
|
const GutenbergBlocksConfig = {
|
2019-07-22 09:39:00 +00:00
|
|
|
...baseConfig,
|
2019-10-06 12:36:15 +00:00
|
|
|
...getMainConfig( { alias: getAlias() } ),
|
|
|
|
};
|
|
|
|
|
2019-10-28 13:53:09 +00:00
|
|
|
const BlocksFrontendConfig = {
|
|
|
|
...baseConfig,
|
|
|
|
...getFrontConfig( { alias: getAlias() } ),
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Currently Legacy Configs are for builds targeting < WP5.3
|
|
|
|
*/
|
|
|
|
|
2019-10-06 12:36:15 +00:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
const LegacyBlocksConfig = {
|
|
|
|
...baseConfig,
|
|
|
|
...getMainConfig( {
|
|
|
|
fileSuffix: 'legacy',
|
|
|
|
resolvePlugins: [
|
|
|
|
new FallbackModuleDirectoryPlugin(
|
|
|
|
'/legacy/',
|
|
|
|
'/',
|
|
|
|
getAlias( { pathPart: 'legacy' } )
|
|
|
|
),
|
2018-11-13 19:21:04 +00:00
|
|
|
],
|
2019-11-01 13:56:14 +00:00
|
|
|
exclude: [ 'all-products', 'price-filter' ],
|
2019-10-06 12:36:15 +00:00
|
|
|
} ),
|
2019-07-22 09:39:00 +00:00
|
|
|
};
|
|
|
|
|
2019-10-06 12:36:15 +00:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
const LegacyFrontendBlocksConfig = {
|
|
|
|
...baseConfig,
|
|
|
|
...getFrontConfig( {
|
|
|
|
fileSuffix: 'legacy',
|
|
|
|
resolvePlugins: [
|
|
|
|
new FallbackModuleDirectoryPlugin(
|
|
|
|
'/legacy/',
|
|
|
|
'/',
|
|
|
|
getAlias( { pathPart: 'legacy' } )
|
|
|
|
),
|
2019-07-22 09:39:00 +00:00
|
|
|
],
|
2019-11-01 13:56:14 +00:00
|
|
|
exclude: [ 'all-products', 'price-filter' ],
|
2019-10-06 12:36:15 +00:00
|
|
|
} ),
|
2018-02-13 19:03:53 +00:00
|
|
|
};
|
|
|
|
|
2019-10-06 12:36:15 +00:00
|
|
|
module.exports = [
|
|
|
|
CoreConfig,
|
|
|
|
GutenbergBlocksConfig,
|
|
|
|
BlocksFrontendConfig,
|
2019-10-28 13:53:09 +00:00
|
|
|
LegacyBlocksConfig,
|
|
|
|
LegacyFrontendBlocksConfig,
|
2019-10-06 12:36:15 +00:00
|
|
|
];
|