-
Notifications
You must be signed in to change notification settings - Fork 3
/
.babelrc.js
59 lines (52 loc) · 1.55 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
"use strict";
const PLUGINS_RE = /^(?:@babel\/|babel-)plugin-.+$/;
const PRESETS_RE = /^@babel\/preset-.+$/;
const NODE_ENV = process.env.NODE_ENV || "development";
const __PROD__ = NODE_ENV === "production";
const __TEST__ = NODE_ENV === "test";
const configs = {
"@babel/plugin-proposal-decorators": {
legacy: true,
},
"@babel/preset-env"(pkg) {
return {
debug: !__TEST__,
shippedProposals: true,
targets: (() => {
let node = (pkg.engines || {}).node;
if (node !== undefined) {
const trimChars = "^=>~";
while (trimChars.includes(node[0])) {
node = node.slice(1);
}
return { node: node };
}
})(),
useBuiltIns: "@babel/polyfill" in (pkg.dependencies || {}) && "usage",
};
},
};
const getConfig = (key, ...args) => {
const config = configs[key];
return config === undefined
? {}
: typeof config === "function"
? config(...args)
: config;
};
const plugins = {};
const presets = {};
const pkg = require("./package.json");
Object.keys(pkg.devDependencies || {}).forEach((name) => {
if (!(name in presets) && PLUGINS_RE.test(name)) {
plugins[name] = getConfig(name, pkg);
} else if (!(name in presets) && PRESETS_RE.test(name)) {
presets[name] = getConfig(name, pkg);
}
});
module.exports = {
comments: !__PROD__,
ignore: __TEST__ ? undefined : [/\.spec\.js$/],
plugins: Object.keys(plugins).map((plugin) => [plugin, plugins[plugin]]),
presets: Object.keys(presets).map((preset) => [preset, presets[preset]]),
};