2017-02-16 02:07:29 +00:00
|
|
|
const relativeResolve = require('../root-module-relative-path').default(require)
|
2016-12-21 02:01:56 +00:00
|
|
|
|
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-02-14 01:54:01 +00:00
|
|
|
const envPlugins = {
|
|
|
|
'development': [
|
|
|
|
require.resolve('babel-plugin-transform-react-jsx-source')
|
|
|
|
],
|
|
|
|
'production': [
|
|
|
|
require.resolve('babel-plugin-transform-react-remove-prop-types')
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2017-05-06 07:07:50 +00:00
|
|
|
const plugins = envPlugins[process.env.NODE_ENV] || envPlugins['development']
|
2017-02-10 19:05:13 +00:00
|
|
|
|
2017-10-07 06:38:59 +00:00
|
|
|
module.exports = (context, opts = {}) => ({
|
2016-12-21 02:01:56 +00:00
|
|
|
presets: [
|
2017-04-18 13:58:34 +00:00
|
|
|
[require.resolve('babel-preset-env'), {
|
2017-10-07 06:38:59 +00:00
|
|
|
modules: false,
|
|
|
|
...opts['preset-env']
|
2017-02-08 12:05:25 +00:00
|
|
|
}],
|
2016-12-21 02:01:56 +00:00
|
|
|
require.resolve('babel-preset-react')
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
require.resolve('babel-plugin-react-require'),
|
2017-04-17 15:33:40 +00:00
|
|
|
require.resolve('./plugins/handle-import'),
|
2016-12-21 02:01:56 +00:00
|
|
|
require.resolve('babel-plugin-transform-object-rest-spread'),
|
|
|
|
require.resolve('babel-plugin-transform-class-properties'),
|
2017-10-15 17:54:57 +00:00
|
|
|
[require.resolve('babel-plugin-transform-runtime'), opts['transform-runtime'] || {}],
|
|
|
|
[require.resolve('styled-jsx/babel'), styledJsxOptions(opts['styled-jsx'])],
|
2017-02-14 01:54:01 +00:00
|
|
|
...plugins,
|
2016-12-21 02:01:56 +00:00
|
|
|
[
|
|
|
|
require.resolve('babel-plugin-module-resolver'),
|
|
|
|
{
|
|
|
|
alias: {
|
2017-02-16 02:07:29 +00:00
|
|
|
'babel-runtime': relativeResolve('babel-runtime/package'),
|
|
|
|
'next/link': relativeResolve('../../../lib/link'),
|
|
|
|
'next/prefetch': relativeResolve('../../../lib/prefetch'),
|
|
|
|
'next/css': relativeResolve('../../../lib/css'),
|
2017-04-17 20:15:50 +00:00
|
|
|
'next/dynamic': relativeResolve('../../../lib/dynamic'),
|
2017-02-16 02:07:29 +00:00
|
|
|
'next/head': relativeResolve('../../../lib/head'),
|
|
|
|
'next/document': relativeResolve('../../../server/document'),
|
|
|
|
'next/router': relativeResolve('../../../lib/router'),
|
|
|
|
'next/error': relativeResolve('../../../lib/error')
|
2016-12-21 02:01:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
2017-10-07 06:38:59 +00:00
|
|
|
})
|