-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.js
62 lines (58 loc) · 1.84 KB
/
webpack.config.js
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
const path = require( 'path' );
const webpackConfig = require( '@wordpress/scripts/config/webpack.config' );
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
const CLIENT_DIR = path.resolve( __dirname, 'client' );
const baseResolveModules = webpackConfig.resolve.modules || [];
module.exports = function ( env, argv ) {
const { outputLibraryExport } = argv;
const config = {
...webpackConfig,
output: {
...webpackConfig.output,
...( outputLibraryExport
? { libraryExport: outputLibraryExport }
: {} ),
},
resolve: {
...webpackConfig.resolve,
modules: [ ...baseResolveModules, CLIENT_DIR, 'node_modules' ],
},
plugins: [
// this might be a little risky, but it's the only way to make the multiple builds not clear out each other's files
new CleanWebpackPlugin( {
cleanAfterEveryBuildPatterns: [],
cleanStaleWebpackAssets: false,
cleanOnceBeforeBuildPatterns: [],
} ),
...webpackConfig.plugins.filter(
( plugin ) =>
plugin.constructor.name !==
'DependencyExtractionWebpackPlugin' &&
plugin.constructor.name !== 'CleanWebpackPlugin'
),
new DependencyExtractionWebpackPlugin( {
injectPolyfill: true,
requestToExternal: ( request ) => {
if ( request === '@crowdsignalForms/apifetch' ) {
return [ 'crowdsignalForms', 'apiFetch' ];
}
},
requestToHandle: ( request ) => {
// These values must match the names defined in class-crowdsignal-forms-blocks-assets.php
if ( request === '@crowdsignalForms/apifetch' ) {
return 'crowdsignal-forms-apifetch';
}
},
} ),
],
externals: {
...webpackConfig.externals,
jquery: 'jQuery',
react: 'React',
'react-dom': 'ReactDOM',
lodash: 'lodash',
},
};
return config;
};