-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
90 lines (75 loc) · 2.14 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
/**
* Webpack configuration.
*/
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const DependencyExtractionWebpackPlugin = require('@wordpress/dependency-extraction-webpack-plugin');
// JS Directory path.
const JS_DIR = path.resolve(__dirname, 'assets/src/js');
const IMG_DIR = path.resolve(__dirname, 'assets/src/img');
const BUILD_DIR = path.resolve(__dirname, 'assets/build');
const entry = {
blocks: JS_DIR + '/blocks.js',
};
const output = {
path: BUILD_DIR,
filename: 'js/[name].js',
};
/**
* Note: argv.mode will return 'development' or 'production'.
*/
const plugins = (argv) => [
new CleanWebpackPlugin({
cleanStaleWebpackAssets: 'production' === argv.mode, // Automatically remove all unused webpack assets on rebuild, in production.
}),
new DependencyExtractionWebpackPlugin({
injectPolyfill: true,
combineAssets: true,
}),
];
const rules = [
{
test: /\.js$/,
include: [JS_DIR],
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.(png|jpg|svg|jpeg|gif|ico)$/,
use: {
loader: 'file-loader',
options: {
name: 'img/[name].[ext]',
publicPath: process.env.NODE_ENV === 'production' ? '../' : '../../',
},
},
},
{
test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
exclude: [IMG_DIR, /node_modules/],
use: {
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
publicPath: process.env.NODE_ENV === 'production' ? '../' : '../../',
},
},
},
];
module.exports = (env, argv) => ({
entry: entry,
output: output,
/**
* A full SourceMap is emitted as a separate file ( e.g. main.js.map )
* It adds a reference comment to the bundle so development tools know where to find it.
* set this to false if you don't need it
*/
devtool: 'source-map',
module: {
rules: rules,
},
plugins: plugins(argv),
externals: {
jquery: 'jQuery',
},
});