-
Notifications
You must be signed in to change notification settings - Fork 30
/
webpack.config.release.js
183 lines (182 loc) · 5.76 KB
/
webpack.config.release.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
"use strict";
exports.__esModule = true;
const webpack = require("webpack");
const path = require("path");
const HTMLWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const WebpackChunkHash = require("webpack-chunk-hash");
const fs = require("fs/promises");
const { minify } = require("html-minifier-terser");
const minifyOptions = {
collapseWhitespace: true,
minifyJS: true,
};
const config = (async () => ({
// webpack 4 only
mode: "production",
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader",
options: {
minimize: true,
},
},
"sass-loader",
],
}),
},
],
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
entry: {
main: "./Main.tsx",
//冬季
css_blue: "./Themes/wuteng_blue.scss",
//春季(浅)
css_green: "./Themes/forgive_green.scss",
//春季(深)
css_more_green: "./Themes/deep_dark_green.scss",
//夏季
css_summer: "./Themes/summer.scss",
//秋季(橙)
css_autumn_orange: "./Themes/autumn_orange.scss",
//秋季(红)
css_autumn_red: "./Themes/autumn_red.scss",
//双十一
css_singleday: "./Themes/singleday_pink.scss",
//中秋(暗)
css_mid_autumn_dark: "./Themes/mid_autumn_dark.scss",
//中秋(亮)
css_mid_autumn_light: "./Themes/mid_autumn_light.scss",
//小雪(暗)
css_light_snow_dark: "./Themes/light_snow_dark.scss",
//小雪(亮)
css_light_snow_light: "./Themes/light_snow_light.scss",
//春节(暗)
css_spring_festival_dark: "./Themes/spring_festival_dark.scss",
//春节(亮)
css_spring_festival_light: "./Themes/spring_festival_light.scss",
//仲春
css_zhongchun: "./Themes/zhongchun.scss",
//端午
css_dragon_boat_festival: "./Themes/dragon_boat_festival.scss",
//清明
css_qingming: "./Themes/qingming.scss",
//秋色之空(暗)
css_autumn_2022_dark: "./Themes/autumn_2022_dark.scss",
//秋色之空(亮)
css_autumn_2022_light: "./Themes/autumn_2022_light.scss",
//冬日暖雪(暗)
css_winter_2022_dark: "./Themes/winter_2022_dark.scss",
//冬日暖雪(亮)
css_winter_2022_light: "./Themes/winter_2022_light.scss",
//春樱日和(暗)
css_spring_2023_dark: "./Themes/spring_2023_dark.scss",
//春樱日和(亮)
css_spring_2023_light: "./Themes/spring_2023_light.scss",
//重阳(暗)
css_chongyang_dark: "./Themes/chongyang_dark.scss",
//重阳(亮)
css_chongyang_light: "./Themes/chongyang_light.scss",
},
output: {
path: path.resolve(__dirname, "dist/"),
publicPath: "/",
filename: "static/scripts/[name]-[chunkhash:8].js",
},
devtool: false,
externals: {
jquery: "$",
},
plugins: [
new HTMLWebpackPlugin({
template: "Template.ejs",
filename: "static/index.html",
minify: minifyOptions,
inject: false,
templateParameters: {
errorTemplate: await minify((await fs.readFile("error.html")).toString(), minifyOptions),
unsupportedTemplate: await minify((await fs.readFile("unsupported.html")).toString(), minifyOptions),
},
}),
// clean dist
new CleanWebpackPlugin(["dist/static/scripts", "dist/static/content", "dist/static/index.html", "dist/static/reset.html"]),
new CopyWebpackPlugin([
{ from: "node_modules/jquery/dist", to: "static/scripts/lib/jquery/" },
{ from: "node_modules/moment", to: "static/scripts/lib/moment/" },
{ from: "node_modules/bootstrap/dist", to: "static/scripts/lib/bootstrap/" },
{ from: "node_modules/bootstrap-icons", to: "static/scripts/lib/bootstrap-icons/" },
{ from: "node_modules/frowser/build", to: "static/scripts/lib/frowser/" },
{ from: "node_modules/font-awesome", to: "static/content/font-awesome/" },
{ from: "node_modules/mathjax-full", to: "static/scripts/lib/mathjax-full" },
{
from: "node_modules/spectrum-colorpicker/spectrum.js",
to: "static/scripts/lib/spectrum/spectrum.js",
},
{
from: "node_modules/dplayer/dist/DPlayer.min.css",
to: "static/content/DPlayer.min.css",
},
{
from: "node_modules/dplayer/dist/DPlayer.min.css.map",
to: "static/content/DPlayer.min.css.map",
},
{
from: "node_modules/aplayer/dist/APlayer.min.css",
to: "static/content/APlayer.min.css",
},
{
from: "node_modules/aplayer/dist/APlayer.min.css.map",
to: "static/content/APlayer.min.css.map",
},
{
from: "node_modules/hls.js/dist/hls.min.js",
to: "static/content/hls.min.js",
},
{
from: "reset.html",
to: "static/reset.html",
},
]),
new ExtractTextPlugin("static/content/[name]-[chunkhash:8].css"),
new WebpackChunkHash({ algorithm: "md5" }),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
],
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
pure_funcs: ["console.log"],
},
safari10: true,
},
}),
],
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "vendors",
chunks: "all",
},
},
},
},
}))();
exports["default"] = config;