-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbabel.config.cjs
82 lines (79 loc) · 2.46 KB
/
babel.config.cjs
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
module.exports = function(api) {
api.cache.invalidate(() => [process.env.NODE_ENV, process.env.ROLLUP_BUILD_TYPE].join("-"));
const environment = api.env();
const modern = process.env.ROLLUP_BUILD_TYPE === "modern";
/**
* Will be used for the legacy build
*/
const presetEnv = [
"@babel/preset-env",
{
modules: false,
targets: {
browsers: [">0.25%", "not op_mini all"],
},
},
];
/**
* Will be used for the modern build
*/
const presetModule = [
"@babel/preset-modules",
{
loose: true,
},
];
const alwaysUsedPresets = ["@babel/preset-react", "@babel/preset-flow"];
const alwaysUsedPlugins = [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-nullish-coalescing-operator",
];
/**
* Plugins chargés uniquement pour le build legacy
*/
const legacyPlugins = ["@babel/plugin-proposal-object-rest-spread"];
const productionConfig =
modern === "modern"
? {
/**
* Modern build
*/
presets: [presetModule, ...alwaysUsedPresets],
plugins: [...alwaysUsedPlugins],
}
: {
/**
* Legacy build
*/
presets: [presetEnv, ...alwaysUsedPresets],
plugins: [...alwaysUsedPlugins, ...legacyPlugins],
};
const developmentConfig =
modern === "modern"
? {
/**
* Modern build
*/
presets: [presetModule, ...alwaysUsedPresets],
plugins: [...alwaysUsedPlugins, "istanbul"],
}
: {
/**
* Legacy build
*/
presets: [presetEnv, ...alwaysUsedPresets],
plugins: [...alwaysUsedPlugins, ...legacyPlugins, "istanbul"],
};
return {
env: {
production: productionConfig,
development: developmentConfig,
test: {
presets: ["@babel/preset-env", ...alwaysUsedPresets],
plugins: [...alwaysUsedPlugins, ...legacyPlugins],
},
},
};
};