forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
39 lines (35 loc) · 1.09 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
const defines = require('./babel-defines')
function replacementPlugin(env) {
return ['babel-plugin-transform-replace-expressions', {replace: defines[env]}]
}
const sharedPlugins = [
'macros',
'preval',
'add-react-displayname',
'babel-plugin-styled-components',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining'
]
function makePresets(moduleValue) {
return ['@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'] : []),
...sharedPlugins,
replacementPlugin('development')
]
},
production: {
presets: makePresets(false),
plugins: [...sharedPlugins, replacementPlugin('production')]
},
test: {
presets: makePresets('commonjs'),
plugins: [...sharedPlugins, ['@babel/plugin-transform-modules-commonjs'], replacementPlugin('test')]
}
}
}