2017-10-15 17:54:57 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2017-10-07 06:38:59 +00:00
|
|
|
module.exports = (context, opts = {}) => ({
|
2016-12-21 02:01:56 +00:00
|
|
|
presets: [
|
2018-04-03 07:34:07 +00:00
|
|
|
[require('@babel/preset-env'), {
|
2017-10-07 06:38:59 +00:00
|
|
|
modules: false,
|
|
|
|
...opts['preset-env']
|
2017-02-08 12:05:25 +00:00
|
|
|
}],
|
2018-04-03 07:34:07 +00:00
|
|
|
require('@babel/preset-react')
|
2016-12-21 02:01:56 +00:00
|
|
|
],
|
|
|
|
plugins: [
|
2018-04-03 07:34:07 +00:00
|
|
|
require('babel-plugin-react-require'),
|
|
|
|
require('./plugins/handle-import'),
|
2018-06-19 19:48:54 +00:00
|
|
|
[require('@babel/plugin-proposal-class-properties'), opts['class-properties'] || {}],
|
2018-04-03 07:34:07 +00:00
|
|
|
require('@babel/plugin-proposal-object-rest-spread'),
|
|
|
|
[require('@babel/plugin-transform-runtime'), opts['transform-runtime'] || {
|
2018-02-01 11:24:31 +00:00
|
|
|
helpers: false,
|
|
|
|
polyfill: false,
|
|
|
|
regenerator: true
|
|
|
|
}],
|
2018-04-03 07:34:07 +00:00
|
|
|
[require('styled-jsx/babel'), styledJsxOptions(opts['styled-jsx'])],
|
2018-04-18 16:18:06 +00:00
|
|
|
process.env.NODE_ENV === 'production' && require('babel-plugin-transform-react-remove-prop-types')
|
|
|
|
].filter(Boolean)
|
2017-10-07 06:38:59 +00:00
|
|
|
})
|