-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
115 lines (114 loc) · 2.8 KB
/
webpack.config.js
File metadata and controls
115 lines (114 loc) · 2.8 KB
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
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
module.exports = env => {
const isProduction = !!env.WEBPACK_BUILD;
return {
mode: isProduction ? "production" : "development",
entry: {
index: "./src/js/index.js",
js: "./src/js/js.js",
react: "./src/js/react.js",
wordpress: "./src/js/react.js"
},
devtool: isProduction ? false : "inline-source-map",
devServer: {
static: ["src"],
watchFiles: ["src/**/*.*"]
},
optimization: {
minimize: true,
minimizer: ["...", new CssMinimizerPlugin()],
splitChunks: {
cacheGroups: {
commons: {
name: "commons",
chunks: "initial",
minChunks: 2
},
// Extracting all CSS in a single file
styles: {
name: "styles",
type: "css/mini-extract",
chunks: "all",
enforce: true
}
}
}
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
inject: true,
minify: true,
chunks: ["index"],
filename: "index.html"
}),
new HtmlWebpackPlugin({
template: "./src/js.html",
inject: true,
minify: true,
chunks: ["js"],
filename: "js.html"
}),
new HtmlWebpackPlugin({
template: "./src/react.html",
inject: true,
minify: true,
chunks: ["react"],
filename: "react.html"
}),
new HtmlWebpackPlugin({
template: "./src/wordpress.html",
inject: true,
minify: true,
chunks: ["wordpress"],
filename: "wordpress.html"
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
})
],
module: {
rules: [
{
test: /\.html$/i,
loader: "html-loader"
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader"
}
]
},
{
test: /\.(png|svg|jpg|jpeg|gif|mp3|ogg|mp4)$/i,
type: "asset/resource"
}
]
},
output: {
filename: "js/[name].js",
assetModuleFilename: "images/[name].[hash:8][ext][query]",
path: path.resolve(__dirname, "docs"),
publicPath: "",
environment: {
arrowFunction: false
}
},
target: ["web", "es5"]
};
};