feature/share-libs
js 82 lines 1.85 KB
Raw
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-proposal-private-methods',
58 {
59 loose: true
60 }
61 ],
62 [
63 '@babel/plugin-proposal-private-property-in-object',
64 {
65 loose: true
66 }
67 ],
68 [
69 '@babel/plugin-transform-runtime',
70 {
71 helpers: false
72 }
73 ],
74 [
75 '@babel/plugin-transform-regenerator',
76 {
77 async: false
78 }
79 ]
80 ].filter(Boolean)
81 }
82 }