forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 1
/
babel.config.js
46 lines (42 loc) · 1.29 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
const defines = require('./babel-defines')
function replacementPlugin(env) {
return ['babel-plugin-transform-replace-expressions', {replace: defines[env]}]
}
const sharedPlugins = [
'macros',
'preval',
'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: [
...(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')],
},
},
}