/
babel.config.js
38 lines (31 loc) · 978 Bytes
/
babel.config.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
const getPresetOptions = (isTest = false, isProduction = false) => {
if (isTest) return { targets: { node: 'current' } } // for speed
return {
// undefined means parse .browserlistrc by default
targets: !isProduction ? 'last 2 versions' : undefined
}
}
const getBabelConfig = (api) => {
const isDev = api.env('development')
const isTest = api.env('test')
const isProduction = api.env('production')
api.cache.using(() => isDev || isTest)
const presets = [['@babel/preset-env', getPresetOptions(isTest, isProduction)]]
const plugins = [
// Polyfills the runtime needed for async/await, generators, and friends
// https://babeljs.io/docs/en/babel-plugin-transform-runtime
!isTest && [
'@babel/plugin-transform-runtime',
{
corejs: false,
regenerator: true
}
]
].filter(Boolean)
return {
presets: presets,
plugins: plugins,
compact: isProduction
}
}
module.exports = getBabelConfig