forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preset.js
48 lines (43 loc) · 1.22 KB
/
preset.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
// Resolve styled-jsx plugins
function styledJsxOptions (opts) {
if (!opts) {
return {}
}
if (!Array.isArray(opts.plugins)) {
return opts
}
opts.plugins = opts.plugins.map(plugin => {
if (Array.isArray(plugin)) {
const [name, options] = plugin
return [
require.resolve(name),
options
]
}
return require.resolve(plugin)
})
return opts
}
module.exports = (context, opts = {}) => ({
presets: [
[require('@babel/preset-env'), {
modules: false,
...opts['preset-env']
}],
require('@babel/preset-react')
],
plugins: [
require('babel-plugin-react-require'),
require('@babel/plugin-syntax-dynamic-import'),
require('./plugins/react-loadable-plugin'),
[require('@babel/plugin-proposal-class-properties'), opts['class-properties'] || {}],
require('@babel/plugin-proposal-object-rest-spread'),
[require('@babel/plugin-transform-runtime'), {
helpers: false,
regenerator: true,
...opts['transform-runtime']
}],
[require('styled-jsx/babel'), styledJsxOptions(opts['styled-jsx'])],
process.env.NODE_ENV === 'production' && require('babel-plugin-transform-react-remove-prop-types')
].filter(Boolean)
})