-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabel.config.js
109 lines (82 loc) · 2.54 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
module.exports = function getBabelConfig(babelApi) {
const { NODE_ENV } = process.env;
/** Use Babel Cache, based on NODE_ENV */
babelApi.cache.using(() => NODE_ENV);
/** Check if NODE_ENV is 'production' like */
const isProduction = /(production|test)/.test(NODE_ENV);
/** Return Babel Configuration */
return {
/** Set Babel Preset */
presets: [
['@babel/preset-env', {
modules : 'auto',
useBuiltIns : 'usage',
corejs : 3,
targets : {
node : '8.16.0',
browsers : '> 0.25%, not dead'
},
debug: !isProduction
}],
...(isProduction ? [
'minify'
] : [])
],
/** Set Babel Plugins */
plugins: [
...(NODE_ENV !== 'test' ? [
/** https://babeljs.io/docs/en/babel-plugin-transform-runtime */
'@babel/plugin-transform-runtime'
] : []),
/** https://babeljs.io/docs/en/babel-plugin-proposal-class-properties */
'@babel/plugin-proposal-class-properties',
/** https://babeljs.io/docs/en/babel-plugin-proposal-export-default-from */
'@babel/plugin-proposal-export-default-from',
/** https://babeljs.io/docs/en/babel-plugin-proposal-export-namespace-from */
'@babel/plugin-proposal-export-namespace-from',
/**
* Pick only Lodash required module
* https://github.com/lodash/babel-plugin-lodash
*/
'lodash',
/**
* Allow the usage of the optional chaning
* in object, like a.b?.c?
* https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining
*/
'@babel/plugin-proposal-optional-chaining',
/**
* Plugins for Development Environment only
*/
...(!isProduction ? [
/**
* Add Filename and Row for Console.log statement
* https://github.com/peteringram0/babel-plugin-console-source
*/
['console-source',
{
segments: 2
}
]
] : []),
/**
* Plugins for production only
*/
...(isProduction ? [
/**
* Remove Console Log and Debugger
* https://github.com/betaorbust/babel-plugin-groundskeeper-willie
*/
'groundskeeper-willie'
] : [])
],
/** Strip Comments on Development */
comments: !isProduction,
/** Minifiy on Production */
compact: isProduction,
/** Set unambigous source Type */
sourceType: 'unambiguous',
/** Build source map on development */
sourceMap: !isProduction
};
};