-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
112 lines (102 loc) · 2.46 KB
/
webpack.config.js
File metadata and controls
112 lines (102 loc) · 2.46 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
import { fileURLToPath } from "url";
import { dirname } from "path";
import WebpackBar from "webpackbar";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import CopyWebpackPlugin from "copy-webpack-plugin";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const distPath = __dirname + "/dist";
const publicPath = __dirname + "/public";
const htmlPath = publicPath + "/index.html";
const port = 4200;
export default {
entry: "./src/main.tsx",
output: {
path: distPath,
filename: "main.[contenthash].js",
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
alias: {
"@src": __dirname + "/src",
"@assets": __dirname + "/src/assets/",
},
},
module: {
rules: [
{
test: /\.(glsl|vs|fs)$/,
loader: "ts-shader-loader",
},
{
test: /\.(ico|svg|png|jpg|webp)$/, // 匹配不同后缀格式的图片文件
use: [
{
loader: "url-loader",
options: {
limit: 8192, // 图片文件小于8KB时转换为base64编码
name: "images/[name].[ext]", // 输出路径和文件名格式
},
},
],
},
{
test: /\.scss$/,
use: [
"style-loader", // 将CSS注入到页面中的<style>标签
"css-loader", // 将CSS转换为CommonJS模块
"sass-loader", // 将SCSS编译为CSS
],
},
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
],
},
plugins: [
new WebpackBar(),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: htmlPath,
hash: true,
}),
new CopyWebpackPlugin({
patterns: [
{
from: publicPath,
to: ".",
filter: (resourcePath) => {
return resourcePath !== htmlPath;
},
},
],
}),
],
// 禁用控制台消息
stats: false,
infrastructureLogging: { level: "error" },
devServer: {
static: distPath,
host: "0.0.0.0",
port: port,
client: {
// 错误遮罩层提示
overlay: {
errors: true,
runtimeErrors: true,
warnings: false,
},
},
onListening: function () {
console.log(`--------[Dev Server]--------
Preview link:
http://localhost:${port}/
Dist directory:
${distPath}
`);
},
},
};