forked from smooth-code/smooth-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
babel.config.js
52 lines (46 loc) Β· 1.13 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
const { STYLED_ENGINE = 'styled-components', NODE_ENV } = process.env
function getStyledEnginePlugins() {
if (NODE_ENV === 'test') return []
switch (STYLED_ENGINE) {
case 'emotion':
return ['babel-plugin-emotion']
case 'styled-components':
return [['babel-plugin-styled-components', { displayName: false }]]
default:
return []
}
}
module.exports = api => {
api.cache(true)
const config = {
presets: [
['@babel/preset-env', { loose: true, modules: false }],
'@babel/preset-react',
],
plugins: [
...getStyledEnginePlugins(),
[
'babel-plugin-transform-rename-import',
{
replacements: [
{
original: '(.*)styled-engine$',
replacement: `$1styled-engine/${STYLED_ENGINE}`,
},
],
},
],
['@babel/plugin-proposal-class-properties', { loose: true }],
],
}
if (NODE_ENV === 'test') {
return {
...config,
plugins: [
...config.plugins,
['@babel/plugin-transform-modules-commonjs', { loose: true }],
],
}
}
return config
}