468
|
1 module.exports = function(api) {
|
|
2 var validEnv = ['development', 'test', 'production']
|
|
3 var currentEnv = api.env()
|
|
4 var isDevelopmentEnv = api.env('development')
|
|
5 var isProductionEnv = api.env('production')
|
|
6 var isTestEnv = api.env('test')
|
|
7
|
|
8 if (!validEnv.includes(currentEnv)) {
|
|
9 throw new Error(
|
|
10 'Please specify a valid `NODE_ENV` or ' +
|
|
11 '`BABEL_ENV` environment variables. Valid values are "development", ' +
|
|
12 '"test", and "production". Instead, received: ' +
|
|
13 JSON.stringify(currentEnv) +
|
|
14 '.'
|
|
15 )
|
|
16 }
|
|
17
|
|
18 return {
|
|
19 presets: [
|
|
20 isTestEnv && [
|
|
21 '@babel/preset-env',
|
|
22 {
|
|
23 targets: {
|
|
24 node: 'current'
|
|
25 }
|
|
26 }
|
|
27 ],
|
|
28 (isProductionEnv || isDevelopmentEnv) && [
|
|
29 '@babel/preset-env',
|
|
30 {
|
|
31 forceAllTransforms: true,
|
|
32 useBuiltIns: 'entry',
|
|
33 corejs: 3,
|
|
34 modules: false,
|
|
35 exclude: ['transform-typeof-symbol']
|
|
36 }
|
|
37 ]
|
|
38 ].filter(Boolean),
|
|
39 plugins: [
|
|
40 'babel-plugin-macros',
|
|
41 '@babel/plugin-syntax-dynamic-import',
|
|
42 isTestEnv && 'babel-plugin-dynamic-import-node',
|
|
43 '@babel/plugin-transform-destructuring',
|
|
44 [
|
|
45 '@babel/plugin-proposal-class-properties',
|
|
46 {
|
|
47 loose: true
|
|
48 }
|
|
49 ],
|
|
50 [
|
|
51 '@babel/plugin-proposal-object-rest-spread',
|
|
52 {
|
|
53 useBuiltIns: true
|
|
54 }
|
|
55 ],
|
|
56 [
|
|
57 '@babel/plugin-transform-runtime',
|
|
58 {
|
|
59 helpers: false,
|
|
60 regenerator: true,
|
|
61 corejs: false
|
|
62 }
|
|
63 ],
|
|
64 [
|
|
65 '@babel/plugin-transform-regenerator',
|
|
66 {
|
|
67 async: false
|
|
68 }
|
|
69 ]
|
|
70 ].filter(Boolean)
|
|
71 }
|
|
72 }
|