-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbabel.config.js
More file actions
78 lines (74 loc) · 1.87 KB
/
babel.config.js
File metadata and controls
78 lines (74 loc) · 1.87 KB
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
// babel.config.js
module.exports = {
presets: [
[
"@babel/preset-env",
{
targets: {
browsers: ["> 1%", "last 2 versions", "not dead"],
node: "current"
},
useBuiltIns: "usage", // Adds specific imports for polyfills when they are used
corejs: { version: 3, proposals: true }, // Use core-js v3
modules: process.env.MODULES || false // Can be set to 'commonjs' or false (for ESM)
}
]
],
plugins: [
// Plugin to handle dynamic imports
"@babel/plugin-syntax-dynamic-import",
// Transform for optional chaining (?.) operator
"@babel/plugin-proposal-optional-chaining",
// Transform for nullish coalescing (??) operator
"@babel/plugin-proposal-nullish-coalescing-operator",
// Class properties & private methods support
["@babel/plugin-proposal-class-properties", { loose: true }],
["@babel/plugin-proposal-private-methods", { loose: true }],
// Transform for the module resolver
[
"module-resolver",
{
root: ["./src"],
alias: {
"@": "./src"
}
}
]
],
env: {
// Production environment configuration
production: {
plugins: [
// Remove console.log in production
"transform-remove-console"
]
},
// Test environment configuration
test: {
presets: [
[
"@babel/preset-env",
{
targets: { node: "current" },
modules: "commonjs" // Jest requires CommonJS
}
]
],
plugins: [
"babel-plugin-add-module-exports",
"babel-plugin-dynamic-import-node"
]
},
// CommonJS environment configuration
commonjs: {
presets: [
[
"@babel/preset-env",
{
modules: "commonjs"
}
]
]
}
}
};