-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
109 lines (94 loc) · 2.07 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
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
100
101
102
103
104
105
106
107
108
109
/* global process __dirname */
const DEV = 'production' !== process.env.NODE_ENV;
/**
* Plugins
*/
const path = require( 'path' );
const CleanWebpackPlugin = require( 'clean-webpack-plugin' );
const UglifyJsPlugin = require( 'uglifyjs-webpack-plugin' );
const FriendlyErrorsPlugin = require( 'friendly-errors-webpack-plugin' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const OptimizeCssAssetsPlugin = require( 'optimize-css-assets-webpack-plugin' );
const cssnano = require( 'cssnano' );
const StyleLintPlugin = require( 'stylelint-webpack-plugin' );
const BUILD_DIR = path.resolve( __dirname, 'assets/build' );
const JS_MODULES_DIR = path.resolve( __dirname, 'assets/src/js' );
const CSS_MODULES_DIR = path.resolve( __dirname, 'assets/src/css' );
const entry = {
// Entry JS files.
admin: path.resolve( JS_MODULES_DIR, 'Admin/admin.js' ),
};
const output = {
path: BUILD_DIR,
filename: 'js/[name].build.js',
};
/**
* Note: argv.mode will return 'development' or 'production'.
*
* @param {Object} argv
*/
const plugins = () => [
new CleanWebpackPlugin(),
new FriendlyErrorsPlugin( {
clearConsole: false,
} ),
new MiniCssExtractPlugin( {
filename: 'css/[name].css',
} ),
new StyleLintPlugin( {
extends: 'stylelint-config-wordpress/scss',
} ),
];
const rules = [
{
enforce: 'pre',
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'eslint-loader',
},
{
test: /\.js$/,
include: [ JS_MODULES_DIR ],
use: 'babel-loader',
},
{
test: /\.s(a|c)ss$/,
include: [ CSS_MODULES_DIR ],
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader',
],
},
];
const optimization = [
new OptimizeCssAssetsPlugin( {
cssProcessor: cssnano,
} ),
new UglifyJsPlugin( {
cache: false,
parallel: true,
sourceMap: false,
} ),
];
module.exports = () => ( {
entry: entry,
output: output,
plugins: plugins(),
devtool: 'source-map',
module: {
rules,
},
optimization: {
minimizer: optimization,
},
externals: {
jquery: 'jQuery',
},
resolve: {
alias: {
css: CSS_MODULES_DIR,
},
},
} );