Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
56 lines (53 loc) · 1.74 KB
/
Copy pathwebpack.config.js
File metadata and controls
56 lines (53 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
// @woocommerce/* packages are provided by WooCommerce at runtime — don't bundle them.
const WC_EXTERNALS = {
'@woocommerce/components': [ 'wc', 'components' ],
'@woocommerce/csv-export': [ 'wc', 'csvExport' ],
'@woocommerce/currency': [ 'wc', 'currency' ],
'@woocommerce/data': [ 'wc', 'data' ],
'@woocommerce/date': [ 'wc', 'date' ],
'@woocommerce/navigation': [ 'wc', 'navigation' ],
'@woocommerce/number': [ 'wc', 'number' ],
'@woocommerce/settings': [ 'wc', 'wcSettings' ],
'@woocommerce/tracks': [ 'wc', 'tracks' ],
};
const WC_HANDLES = {
'@woocommerce/components': 'wc-components',
'@woocommerce/csv-export': 'wc-csv',
'@woocommerce/currency': 'wc-currency',
'@woocommerce/data': 'wc-store-data',
'@woocommerce/date': 'wc-date',
'@woocommerce/navigation': 'wc-navigation',
'@woocommerce/number': 'wc-number',
'@woocommerce/settings': 'wc-settings',
'@woocommerce/tracks': 'wc-tracks',
};
module.exports = {
...defaultConfig,
entry: {
index: './client/index.js',
},
output: {
...defaultConfig.output,
path: require( 'path' ).resolve( __dirname, 'build' ),
filename: '[name].js',
},
plugins: [
...defaultConfig.plugins.filter(
( p ) => p.constructor.name !== 'DependencyExtractionWebpackPlugin'
),
new DependencyExtractionWebpackPlugin( {
requestToExternal( request ) {
if ( WC_EXTERNALS[ request ] ) {
return WC_EXTERNALS[ request ];
}
},
requestToHandle( request ) {
if ( WC_HANDLES[ request ] ) {
return WC_HANDLES[ request ];
}
},
} ),
],
};