-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
152 lines (146 loc) · 2.9 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ManifestPlugin = require("webpack-manifest-plugin");
const env = process.env.NODE_ENV || "development";
const isProd = env === "production";
const input = path.resolve(__dirname, "src");
const out = path.resolve(__dirname, "_site");
const exclusions = /node_modules/;
const inlineImgLimit = 8192;
const optimization = {
splitChunks: isProd && { chunks: "all" },
minimize: isProd,
// prints more readable module names in the browser console on HMR updates, in dev
namedModules: !isProd,
// prevent emitting assets with errors, in dev
noEmitOnErrors: !isProd
};
const fileLoaderOptions = {
name: "[path][name].[hash].[ext]",
context: input
};
module.exports = {
mode: isProd ? "production" : "development",
entry: {
main: [
path.resolve(input, "js", "main.js"),
path.resolve(input, "css", "main.css")
]
},
output: {
path: out,
filename: "[name].[hash].js",
publicPath: "./"
},
module: {
rules: [
{
test: /\.js$/,
exclude: exclusions,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
}
},
{
test: /\.css$/,
exclude: exclusions,
use: [
{
loader: MiniCssExtractPlugin.loader
},
"css-loader",
"postcss-loader"
]
},
{
include: path.resolve(input, "fonts"),
use: [
{
loader: "file-loader",
options: fileLoaderOptions
}
]
},
{
test: /\.svg$/i,
oneOf: [
{
resourceQuery: /external/,
loader: "file-loader",
options: fileLoaderOptions
},
{
resourceQuery: /inline/,
loader: "svg-url-loader",
options: fileLoaderOptions
},
{
loader: "svg-url-loader",
options: {
...fileLoaderOptions,
limit: inlineImgLimit
}
}
]
},
{
test: /\.(png|jpg)$/i,
oneOf: [
{
resourceQuery: /external/,
loader: "file-loader",
options: fileLoaderOptions
},
{
resourceQuery: /inline/,
loader: "url-loader",
options: {
...fileLoaderOptions,
limit: true
}
},
{
loader: "url-loader",
options: {
...fileLoaderOptions,
limit: inlineImgLimit
}
}
]
}
]
},
devtool: isProd ? false : "eval",
optimization,
plugins: [
new MiniCssExtractPlugin({
filename: "styles.[contenthash].css",
ignoreOrder: false
}),
new ManifestPlugin({
fileName: path.resolve(
input,
"_includes",
".webpack",
"manifest.json"
),
map: file => {
switch (file.name) {
case "main.js":
file.name = "js/main.js";
break;
case "main.css":
file.name = "css/main.css";
break;
default:
// Strip queries like ?external from asset name
file.name = file.name.split("?")[0];
}
return file;
}
})
]
};