# OneOf
目的:提升打包构建的速度---用于大型项目
# 为什么
打包时每个文件都会经过所有 loader 处理,虽然因为 test
正则原因实际没有处理上,但是都要过一遍。比较慢。
# 是什么
顾名思义就是只能匹配上一个 loader, 剩下的就不匹配了。
# 怎么用
const path = require("path");
const ESLintWebpackPlugin = require("eslint-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: "./src/main.js",
output: {
// 其他配置
},
module: {
rules: [
{
oneOf: [
// 其他配置
{
test: /\.js$/,
exclude: /node_modules/, // 排除node_modules代码不编译
loader: "babel-loader",
},
],
},
],
},
plugins: [
// 其他配置
],
// 开发服务器
devServer: {
// 其他配置
},
mode: "development",
};
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
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
生产模式也是如此配置。