forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
35 lines (31 loc) · 1000 Bytes
/
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
const defines = require('./babel-defines')
function replacementPlugin(env) {
return ['babel-plugin-transform-replace-expressions', {replace: defines[env]}]
}
const sharedPlugins = [
'macros',
'dev-expression',
'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: [...sharedPlugins, replacementPlugin('development')],
},
production: {
presets: makePresets(false),
plugins: [...sharedPlugins, replacementPlugin('production')],
},
test: {
presets: makePresets('commonjs'),
plugins: [...sharedPlugins, ['@babel/plugin-transform-modules-commonjs'], replacementPlugin('test')],
},
},
}