-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
79 lines (77 loc) · 1.7 KB
/
webpack.config.js
File metadata and controls
79 lines (77 loc) · 1.7 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
const { resolve } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpackBaseConfig = {
// 入口配置,指定入口文件为 src/index.tsx
entry: {
main: resolve(__dirname, './src/index.jsx')
},
// 输出配置,指定输出目录为项目根目录下的 dist 文件夹
output: {
path: resolve(process.cwd(), 'dist'),
filename: '[name].[contenthash].js',
clean: true,
publicPath: '/'
},
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
},
// 模块配置
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'swc-loader',
options: {
jsc: {
parser: {
syntax: "ecmascript",
jsx: true
},
transform: {
react: {
runtime: 'automatic'
}
}
}
}
}
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader']
},
{
// 处理图片资源文件
test: /\.(png|jpg|jpeg|gif|svg)$/,
// 使用 asset 资源模块处理
type: 'asset',
}
]
},
// cache: {
// type: 'filesystem'
// }
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
filename: 'index.html',
inject: true
})
],
devServer: {
static: {
directory: resolve(__dirname, 'dist'),
},
hot: true,
open: true,
compress: true,
port: 3000,
historyApiFallback: true
}
}
// 合并基础配置和环境特定配置
module.exports = webpackBaseConfig