-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path.babel-preset.js
57 lines (51 loc) · 1.38 KB
/
.babel-preset.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
const r = m => require.resolve(m)
function preset(context, options = {}) {
const { browser = false, debug = false } = options
const { NODE_ENV, BABEL_ENV } = process.env
const PRODUCTION = (BABEL_ENV || NODE_ENV) === 'production'
const browserConfig = {
useBuiltIns: false,
targets: {
browsers: PRODUCTION
? [`last 4 versions`, `safari >= 7`, 'ie >= 9']
: [`last 2 versions`, `not ie <= 11`, `not android 4.4.3`],
},
}
const nodeConfig = {
targets: {
node: PRODUCTION ? 6.0 : 'current',
},
}
return {
presets: [
[
r('@babel/preset-env'),
Object.assign(
{
loose: true,
debug: !!debug,
useBuiltIns: 'entry',
shippedProposals: true,
modules: 'commonjs',
},
browser ? browserConfig : nodeConfig
),
],
[r('@babel/preset-react'), { development: !PRODUCTION }],
r('@babel/preset-flow'),
],
plugins: [
r('@babel/plugin-proposal-class-properties'),
r('@babel/plugin-proposal-optional-chaining'),
[
r('@babel/plugin-transform-runtime'),
{
// we are only polyfilling the node environment
// so we need to enable the runtime replacements for the browser preset
// polyfill: !!browser,
},
],
],
}
}
module.exports = preset