-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathwebpack.config.js
More file actions
99 lines (93 loc) · 2.78 KB
/
webpack.config.js
File metadata and controls
99 lines (93 loc) · 2.78 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const path = require( 'path' );
const CustomTemplatedPathPlugin = require( './packages/custom-templated-path-webpack-plugin' );
const DependencyExtractionWebpackPlugin = require( './packages/dependency-extraction-webpack-plugin' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const NODE_ENV = process.env.NODE_ENV || 'development';
const packages = {
'block-editor': 'packages/block-editor',
components: 'packages/components',
'core-data': 'packages/core-data',
data: 'packages/data',
fields: 'packages/fields',
icons: 'packages/icons',
'rule-engine': 'packages/rule-engine',
'settings-page': 'packages/settings-page',
utils: 'packages/utils',
'widget-editor': 'packages/widget-editor',
};
const config = {
...defaultConfig,
// Maps our buildList into a new object of { key: build.entry }.
entry: Object.entries( packages ).reduce(
( entry, [ packageName, packagePath ] ) => {
entry[ packageName ] = path.resolve(
process.cwd(),
packagePath,
'src'
);
return entry;
},
{}
),
output: {
filename: ( data ) => {
const name = data.chunk.name;
return '[name].js';
},
path: path.resolve( process.cwd(), 'dist' ),
devtoolNamespace: 'content-control/core',
devtoolModuleFilenameTemplate:
'webpack://[namespace]/[resource-path]?[loaders]',
library: {
// Expose the exports of entry points so we can consume the libraries in window.wc.[modulename] with WooCommerceDependencyExtractionWebpackPlugin.
name: [ 'contentControl', '[modulename]' ],
type: 'window',
},
// A unique name of the webpack build to avoid multiple webpack runtimes to conflict when using globals.
uniqueName: '__contentControlAdmin_webpackJsonp',
},
resolve: {
extensions: [ '.json', '.js', '.jsx', '.ts', '.tsx' ],
alias: {
...defaultConfig.resolve.alias,
...Object.entries( packages ).reduce(
( alias, [ packageName, packagePath ] ) => {
alias[ `@content-control/${ packageName }` ] = path.resolve(
__dirname,
packagePath
);
return alias;
},
{}
),
},
},
plugins: [
...defaultConfig.plugins.filter(
( plugin ) =>
plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
),
new CustomTemplatedPathPlugin( {
modulename( outputPath, data ) {
const entryName = data.chunk.name;
if ( entryName ) {
// Convert the dash-case name to a camel case module name.
// For example, 'csv-export' -> 'csvExport'
return entryName.replace( /-([a-z])/g, ( match, letter ) =>
letter.toUpperCase()
);
}
return outputPath;
},
} ),
new DependencyExtractionWebpackPlugin( {
// injectPolyfill: true,
// useDefaults: true,
} ),
],
optimization: {
...defaultConfig.optimization,
minimize: NODE_ENV !== 'development',
},
};
module.exports = config;