-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
99 lines (98 loc) · 3.28 KB
/
webpack.config.js
File metadata and controls
99 lines (98 loc) · 3.28 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
// 引入包
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',
// 告诉 webpack 打包不使用箭头函数
environment: {
arrowFunction: false,
const:false
},
},
// 打包时所用模块
module: {
rules: [
{
// 规则生效的文件
test: /\.ts$/,
// 要使用的 loader
use: [
// 配置 babel
{
// 指定 loader
loader: 'babel-loader',
// 设置babel
options: {
// 设置预定义的环境
presets: [
[
// 指定环境插件
'@babel/preset-env',
// 配置信息
{
// 兼容的浏览器
targets: {
chrome: '88',
ie: '8',
},
// 指定 corejs 版本
corejs: '3',
// 使用 corejs 方式
// usage 表示按需加载
useBuiltIns: 'usage',
},
],
],
},
},
'ts-loader',
],
// 要排除编译的文件
exclude: /node_modules/,
},
{
test: /\.less$/,
use: [
'style-loader',
'css-loader',
// 引入 postcss
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
[
'postcss-preset-env',
{
browsers: 'last 2 versions',
},
],
],
},
},
},
'less-loader',
],
},
],
},
// 打包时所用插件
plugins: [
new HtmlWebpackPlugin({
// title:'自定义属性内容',
template: './src/index.html',
}),
new CleanWebpackPlugin(),
],
// 设置引用模块
resolve: {
extensions: ['.ts', '.js'],
},
mode: 'production',
}