-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
43 lines (36 loc) · 1.34 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
/* eslint-disable complexity */
const MIN_BABEL_VERSION = 7;
const defaultAlwaysOnTransforms = ['@babel/plugin-proposal-nullish-coalescing-operator'];
module.exports = function preset(api, opts) {
api.assertVersion(MIN_BABEL_VERSION);
const transformRuntime = opts.transformRuntime || false;
const useBuiltIns = opts.useBuiltIns || false;
const angularSupport = opts.angular || false;
const typeScript = opts.typeScript || false;
const corejs = opts.corejs || '2';
const reactConfig = opts.react;
const envConfig = {
useBuiltIns,
include: angularSupport
? [...defaultAlwaysOnTransforms, 'transform-parameters'] // This fixes an issue with transforming Angular code like `constructor(...args)`
: defaultAlwaysOnTransforms
};
if (useBuiltIns) {
envConfig.corejs = corejs;
}
return {
presets: [
[require('@babel/preset-react'), reactConfig],
[require('@babel/preset-env'), envConfig],
typeScript
? [require('@babel/preset-typescript'), {allowDeclareFields: true}]
: null
].filter(it => !!it),
plugins: [
require('@babel/plugin-transform-strict-mode'),
// Optional transformations
angularSupport ? require('babel-plugin-angularjs-annotate') : null,
transformRuntime ? require('@babel/plugin-transform-runtime') : null
].filter(it => !!it)
};
};