-
Notifications
You must be signed in to change notification settings - Fork 164
/
babel.config.js
57 lines (51 loc) · 1.52 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
const defines = require('./babel-defines')
function replacementPlugin(env) {
return ['babel-plugin-transform-replace-expressions', { replace: defines[env] }]
}
const sharedPlugins = [
'preval',
// install others if you need:
// 'add-react-displayname',
// 'babel-plugin-styled-components',
// '@babel/plugin-proposal-nullish-coalescing-operator',
// '@babel/plugin-proposal-optional-chaining',
[
'module-resolver',
{
root: ['./'],
extensions: ['ts', 'tsx', '.js', '.jsx', '.json', '.svg', '.png', '.jpg', '.jpeg'],
alias: {
'@': './src/'
}
}
]
]
function makePresets(moduleValue) {
return ['@babel/preset-env', '@babel/preset-typescript', ['@babel/preset-react', { modules: moduleValue }]]
}
module.exports = {
env: {
development: {
presets: makePresets(process.env.BABEL_MODULE || false),
plugins: [
...(process.env.BABEL_MODULE === 'commonjs'
? ['@babel/plugin-transform-modules-commonjs']
: process.env.STORYBOOK
? []
: [
'transform-commonjs' // theme-preval is commonjs and needs to be transformed to esm
]),
...sharedPlugins,
replacementPlugin('development')
]
},
production: {
presets: makePresets(false),
plugins: [...sharedPlugins, replacementPlugin('production')]
},
test: {
presets: makePresets('commonjs'),
plugins: [...sharedPlugins, ['@babel/plugin-transform-modules-commonjs'], replacementPlugin('test')]
}
}
}