-
Notifications
You must be signed in to change notification settings - Fork 10
/
.babelrc.js
61 lines (58 loc) · 1.5 KB
/
.babelrc.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
let babel_env = process.env["BABEL_ENV"];
let loose = false,
modules = false,
useESModules = false;
switch (babel_env) {
case "commonjs":
loose = true;
modules = "cjs";
useESModules = false;
break;
case "es":
loose = true;
modules = false;
useESModules = true;
break;
case "umd":
loose = false;
modules = false;
useESModules = false;
break;
}
//useBuiltIns: true 如果为 true 且引入了polyfill
// (import "babel-polyfill")的话,插件 会根据 targets 的配置,重写 import "babel-polyfill" ,
//只引入对应环境必须的 "babel-polyfill" 的子模块,减少了多余的代码引入
const presets = [["@babel/preset-env", { loose, modules }], "@babel/preset-react"];
const plugins = [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread",
["@babel/plugin-transform-runtime", { useESModules }],
[
"@babel/plugin-proposal-decorators",
{
legacy: true
}
]
];
// 预览情况下添加对 antd 按需加载样式的支持
if (babel_env === "preview") {
plugins.push([
"import",
{
libraryName: "antd",
libraryDirectory: "es",
style: "css" // `style: true` 会加载 less 文件
},
"ant-design"
]);
// plugins.push([
// "import",
// {
// libraryName: "hiynn-design",
// libraryDirectory: "es",
// style: true // `style: true` 会加载 less 文件
// },
// "hiynn-design"
// ]);
}
module.exports = { presets, plugins };