-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
156 lines (149 loc) · 4.71 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
153
154
155
156
const path = require("path");
//Plugins
const CssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const HtmlPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const webpack = require('webpack');
const pkg = require('./package.json');
const devMode = process.env.NODE_ENV != "production";
const license_banner = `
${pkg.name} ${pkg.version} distribution
Copyright (c) 2024, ${pkg.author}
All rights reserved.
This source code is licensed under the GNU license found in the
LICENSE file in the root directory of this source tree.
License information can be found in the LICENSE.shikai file.
`
module.exports = {
entry: {
index: path.resolve("./src/js/index.jsx"),
monitor: path.resolve("./src/js/monitor.jsx")
},
output: {
filename: "[name].js",
path: path.resolve("./dist")
},
mode: devMode ? "development" : "production",
plugins: [
new HtmlPlugin({
filename: "index.html",
template: "src/index.html",
chunks: ["index"],
inject: "body"
}),
new HtmlPlugin({
filename: "monitor.html",
template: "src/index.html",
chunks: ["monitor"],
inject: "body"
}),
new CssExtractPlugin({
filename: "[name].css"
}),
new CopyPlugin({
patterns: [{
from: "./src/assets/runtime",
to: "./assets"
}]
}),
new webpack.BannerPlugin({banner: license_banner})
],
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/i,
use: [
devMode ? "style-loader" : CssExtractPlugin.loader,
{
loader: "css-loader",
options: {
sourceMap: devMode
}
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
[
"autoprefixer"
]
]
}
}
},
{
loader: "sass-loader",
options: {
sourceMap: devMode,
sassOptions: {
outputStyle: devMode ? "expanded" : "compressed"
}
}
}
]
},
{
test: /\.(js|jsx)$/i,
exclude: /node_module/ ,
use: {
loader: "babel-loader",
options: {
cacheDirectory: true,
envName: devMode ? "development" : "production"
}
}
},
{
test: /\.svg$/,
use: [{loader: "svg-react-loader"}]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: "asset/resource",
generator: {filename: "assets/fonts/[name][ext]"}
},
{
test: /\.(yml)$/i,
type: "asset/resource",
generator: {filename: "[name][ext]"}
}
]//noParse: /\.(woff|woff2|eot|ttf|otf)$/
},
resolve: {
extensions: [".js", ".min.js", ".jsx"],
mainFiles: ["index"],
modules: ["src/js", "./node_modules", "src"]
},
optimization: {
minimize: !devMode,
minimizer: [
new CssMinimizerPlugin(),
new TerserPlugin({
terserOptions: {
format: {
comments: false
}
},
extractComments: {
filename: "LICENSE.shikai",
condition: /^\**!|@preserve|@license|@cc_on/i,
banner: license_banner
}
})
],
splitChunks: {
cacheGroups: {
styles: {
name: "styles",
type: "css/mini-exctract",
chunks: "all",
enforce: true
}
}
}
},
devtool: devMode ? "eval" : false
};