This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (72 loc) · 1.89 KB
/
index.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
module.exports = (
api,
options = {
jsx: true,
},
) => {
// https://babeljs.io/docs/en/babel-preset-env
let envOptions = {
targets: options.targets || {
esmodules: true
},
spec: options.spec,
loose: options.loose || false,
modules: options.modules || false,
debug: options.debug || false,
include: options.include,
exclude: options.exclude || [],
useBuiltIns: options.useBuiltIns || "usage",
forceAllTransforms: options.forceAllTransforms,
configPath: options.configPath,
ignoreBrowserslistConfig: true,
shippedProposals: options.shippedProposals,
corejs: {
version: "core-js@3",
},
};
let presets = [];
let plugins = [];
if (options.jsx) {
presets.push([
require("@vue/babel-preset-jsx"),
typeof options.jsx === "object" ? options.jsx : {},
]);
}
plugins.push(["@babel/plugin-syntax-dynamic-import"]);
// https://babeljs.io/docs/en/next/babel-plugin-transform-runtime.html
plugins.push([
"@babel/plugin-transform-runtime",
{
useESModules: true,
helpers: envOptions.useBuiltIns === "usage",
regenerator: envOptions.useBuiltIns !== "usage",
// polyfills are injected by preset-env & polyfillsPlugin, so no need to add them again
corejs: false,
},
]);
presets.unshift(["@babel/preset-env", envOptions]);
return {
sourceType: "unambiguous",
overrides: [
{
exclude: [/@babel[\/|\\\\]runtime/, /core-js/],
presets,
plugins,
},
{
// there are some untranspiled code in @babel/runtime
// https://github.com/babel/babel/issues/9903
include: [/@babel[\/|\\\\]runtime/],
presets: [
[
require("@babel/preset-env"),
{
useBuiltIns: envOptions.useBuiltIns,
corejs: 3,
},
],
],
},
],
};
};