forked from Automattic/WP-Job-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
49 lines (46 loc) · 1.23 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
/* global require, module, process, __dirname */
const cleanWebpackPlugin = require( 'clean-webpack-plugin' );
const lodashModuleReplacementPlugin = require( 'lodash-webpack-plugin' );
const miniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const glob = require( 'glob' );
const entryArray = glob.sync( './assets/blocks/**/index.jsx' );
const entryObject = entryArray.reduce( ( acc, item ) => {
let name = item.replace( './assets/blocks/', '' ).replace( '/index.jsx', '' );
acc[ name ] = item;
return acc;
}, {} );
const webpackConfig = ( env, argv ) => {
return {
entry: entryObject,
output: {
filename: 'build/blocks/[name]/index.js',
path: __dirname,
},
module: {
rules: [
{
test: /.jsx$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.scss$/,
include: [ /assets\/blocks/ ],
use: [
argv.mode !== 'production' ? 'style-loader' : miniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
],
},
],
},
plugins: [
new cleanWebpackPlugin( [ 'build/blocks' ] ),
new lodashModuleReplacementPlugin(),
new miniCssExtractPlugin( {
filename: 'build/blocks/[name]/style.css',
} ),
],
};
};
module.exports = webpackConfig;