-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
98 lines (91 loc) · 1.81 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
const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
module.exports = {
//指定入口文件
entry: "./src/index.ts",
//指定打包文件输出位置
output: {
//指定打包文件目录
path: path.resolve(__dirname, 'dist'),
//打包后的文件名字
filename: "bundle.js"
},
mode: 'development',
//指定webpack打包时使用的模块
module: {
//指定loader的规则
rules: [
{
//test指定的是规则生效的文件
test: /\.ts$/,
//要使用的loader
use: [
//配置babel
{
//指定加载器
loader: "babel-loader",
//配置babel
options: {
// 设置预置环境
presets: [
[
//指定环境的插件
"@babel/preset-env",
// 配置信息
{
targets: {
//需要兼容的浏览器
"chrome": "92"
},
// 指定corejs的版本
"corejs": "3",
// 使用corejs的方式 "usage"(按需加载)
"useBuiltIns": "usage"
}
]
]
}
},
'ts-loader'],
//要排除的文件
exclude: /node_modules/
},
//设置less文件的处理
{
test: /.less$/,
use: [
"style-loader",
"css-loader",
//引入postcss
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
[
"postcss-preset-env",
{
browsers: 'last 2 versions'
}
]
]
}
}
},
"less-loader"
]
}
]
},
//配置webpack的插件
plugins: [
new CleanWebpackPlugin(),
new HTMLWebpackPlugin({
template: "./src/index.html"
})
],
resolve: {
extensions: ['.js', '.ts']
}
}