-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
98 lines (97 loc) · 2.33 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");
module.exports = {
mode: "development",
//入口文件
entry: "./src/index.ts",
//出口文件
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
//告诉webpack不是用箭头函数,和const, ie 老版本不兼容const和arrow function
environment: {
arrowFunction: false,
const: false,
},
},
//使用的插件
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
}),
],
module: {
rules: [
{
//
test: /\.ts$/,
//使用的loader(从下向上执行)
use: [
//配置babel
{
//指定加载器
loader: "babel-loader",
//设置babel
options: {
//设置定义环境
presets: [
[
//环境插件
"@babel/preset-env",
//配置文件
{
//兼容浏览器版本
targets: {
chrome: "58",
ie: "11",
},
//指定corejs的版本
corejs: "3",
//使用corejs的方式 usage按需加载
useBuiltIns: "usage",
},
],
],
},
},
"ts-loader",
],
exclude: /node_modules/,
},
{
test: /\.less$/,
use: [
"style-loader",
"css-loader",
//引入postcss(解决不同浏览器对css的兼容性问题)
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
[
"postcss-preset-env",
{
browsers: "last 3 versions",
},
],
],
},
},
},
"less-loader", //将less style编译成css
],
exclude: /node_modules/,
},
],
},
devServer: {
contentBase: "./dist",
//是否实时监听
inline: true,
},
//设置引用的模块
resolve: {
extensions: [".ts", ".js"],
},
};