-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
63 lines (58 loc) · 1.61 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
63
const path = require( 'path' );
const webpack = require( 'webpack' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const isProduction = process.env.NODE_ENV === 'production';
/* Plugins */
const defaultPlugins = defaultConfig.plugins
.map( ( plugin ) => {
const name = plugin.constructor.name;
// Remove LiveReloadPlugin if in development mode b/c using browsersync + HMR
if ( name.includes( 'LiveReloadPlugin' ) ) {
return false;
}
// Remove CleanWebpackPlugin b/c it tailwindcss files
if ( name.includes( 'CleanWebpackPlugin' ) ) {
return false;
}
return plugin;
} )
.filter( ( plugin ) => plugin );
const config = {
...defaultConfig,
mode: isProduction ? 'production' : 'development',
devtool: 'source-map',
entry: {
index: isProduction
? [ path.resolve( process.cwd(), `src/index.js` ) ]
: [
path.resolve( process.cwd(), `./src/index.js` ),
'webpack-hot-middleware/client?name=index&timeout=20000&reload=true&overlay=true',
],
},
output: isProduction
? {
path: path.resolve( process.cwd(), `./build` ),
filename: '[name].js',
// needed to add this to resolve issues that arise
// if building/activating multiple block plugins
jsonpFunction: 'sidebar',
}
: {
publicPath: `/build/`,
path: path.resolve( process.cwd(), `./build` ),
filename: '[name].js',
},
module: {
...defaultConfig.module,
},
optimization: {
...defaultConfig.optimization,
},
plugins: isProduction
? [ ...defaultPlugins ]
: [
...defaultPlugins,
new webpack.HotModuleReplacementPlugin(),
],
};
module.exports = config;