-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.base.ts
151 lines (130 loc) · 3.44 KB
/
webpack.config.base.ts
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
import path from 'path'
import webpack from 'webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import WebpackPwaManifest from "webpack-pwa-manifest"
import CopyWebpackPlugin from 'copy-webpack-plugin'
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
import WorkboxPlugin from "workbox-webpack-plugin"
import pkgInfo from "./package.json"
import BundleAnalyzerPlugin from "webpack-bundle-analyzer"
const config: webpack.Configuration = {
entry: {
app: path.resolve(__dirname, './src/AppLoader.ts'),
"404": path.resolve(__dirname, './src/404redirector.ts')
},
output: {
filename: 'js/[name].bundle.[hash].js',
chunkFilename: 'js/[name].chunk.[hash].js',
path: path.resolve(__dirname, './dist'),
publicPath: "/",
},
module: {
rules: [
{ test: /\.(ts|tsx)?$/, loader: 'ts-loader' },
{
test: /\.css$/,
use: [
{
loader: 'style-loader' // Put css to <style/>
},
{
loader: 'css-loader?modules=true' // parse css
}
]
},
{
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)?$/,
use: {
loader: 'url-loader?limit=100000&name=images/[name]_[hash:8].[ext]'
}
},
]
},
// externals: helper.EXTERNALS,
plugins: [
new webpack.ProgressPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "./src/AppPage.html"),
favicon: path.resolve(__dirname, "assets/icons/icon.ico"),
minify: { // 压缩HTML文件
removeComments: true, // 移除HTML中的注释
collapseWhitespace: true, // 删除空白符与换行符
minifyCSS: true// 压缩内联css
},
chunks: ["app"]
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "./src/AppPage.html"),
favicon: path.resolve(__dirname, "assets/icons/icon.ico"),
filename: "404.html",
title: "404redictor",
minify: { // 压缩HTML文件
removeComments: true, // 移除HTML中的注释
collapseWhitespace: true, // 删除空白符与换行符
minifyCSS: true// 压缩内联css
},
chunks: ["404"]
}),
//@ts-ignore
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, "./public"),
to: path.resolve(__dirname, "./dist")
},
{
from: path.resolve(__dirname, "./assets"),
to: path.resolve(__dirname, "./dist/assets")
}
]
}),
//@ts-ignore
new CleanWebpackPlugin(),
//@ts-ignore
// new BundleAnalyzerPlugin({
// analyzerMode:"static"
// }),
//https://stackoverflow.com/questions/65018431/webpack-5-uncaught-referenceerror-process-is-not-defined
new webpack.ProvidePlugin({
process: 'process/browser',
}),
//@ts-ignore
new WebpackPwaManifest({
name: pkgInfo.name,
short_name: pkgInfo.name,
description: pkgInfo.description,
background_color: "#ffffff",
icons: [
{
src: path.resolve(__dirname, "assets/icons/icon.png"),
destination: "icons/uni",
sizes: [96, 128, 192, 256, 384, 512],
},
{
src: path.resolve(__dirname, "assets/icons/apple-icon.png"),
destination: "icons/apple",
size: 152,
ios: true
},
],
}),
new WorkboxPlugin.GenerateSW({ swDest: "js/sw.js" }),
],
optimization: {
splitChunks: {
chunks: 'async',
minSize: 20000,
minRemainingSize: 0,
}
},
devServer: {
contentBase: path.join(__dirname, './dist'),
open: false,
host: "0.0.0.0",
port: 5000,
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.css', '.jpg', '.png', '.ico', '.gif', '.json']
}
};
export default config;