Commit 559c2525 authored by Tom MacWright's avatar Tom MacWright Committed by Tim Neutkens

Configurable opts for babel-preset-env + babel-plugin-transform-runtime (#2991)

* Configurable opts for babel-preset-env + babel-plugin-transform-runtime

This adds `preset-env` and `transform-runtime` options to the
`next/babel` Babel preset, which are then passed through to those
presets and transforms. This allows configuration to keep next.js
from the default 'maximum' transform, and instead use built-in
implementations of globals, classes, async, and other commonly-supported
features.

Fixes #2989

* Use spread notation instead of Object.assign
parent a761aa5b
{
"env": {
"production": {
"presets": [
"next/babel"
]
},
"development": {
"presets": [
["next/babel", {
"preset-env": {
"targets": {
"browsers": "last 1 Chrome version",
"node": true
}
},
"transform-runtime": {
"regenerator": false,
"useBuiltIns": true,
"polyfill": false
}
}]
]
}
}
}
{
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^15.4.2",
"react-dom": "^15.4.2"
}
}
import {Component} from 'react'
function * generatorMethod () {
yield 1
}
async function fooBar () {
for (let val of generatorMethod()) {
return val
}
}
export default class Index extends Component {
async otherMethod () {
await fooBar()
}
render () {
const foo = new Map([['cats', 'dogs']])
return <h1>Garbage {foo.get('cats')}</h1>
}
}
...@@ -11,10 +11,11 @@ const envPlugins = { ...@@ -11,10 +11,11 @@ const envPlugins = {
const plugins = envPlugins[process.env.NODE_ENV] || envPlugins['development'] const plugins = envPlugins[process.env.NODE_ENV] || envPlugins['development']
module.exports = { module.exports = (context, opts = {}) => ({
presets: [ presets: [
[require.resolve('babel-preset-env'), { [require.resolve('babel-preset-env'), {
modules: false modules: false,
...opts['preset-env']
}], }],
require.resolve('babel-preset-react') require.resolve('babel-preset-react')
], ],
...@@ -23,7 +24,8 @@ module.exports = { ...@@ -23,7 +24,8 @@ module.exports = {
require.resolve('./plugins/handle-import'), require.resolve('./plugins/handle-import'),
require.resolve('babel-plugin-transform-object-rest-spread'), require.resolve('babel-plugin-transform-object-rest-spread'),
require.resolve('babel-plugin-transform-class-properties'), require.resolve('babel-plugin-transform-class-properties'),
require.resolve('babel-plugin-transform-runtime'), [require.resolve('babel-plugin-transform-runtime'),
opts['transform-runtime'] || {}],
require.resolve('styled-jsx/babel'), require.resolve('styled-jsx/babel'),
...plugins, ...plugins,
[ [
...@@ -43,4 +45,4 @@ module.exports = { ...@@ -43,4 +45,4 @@ module.exports = {
} }
] ]
] ]
} })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment