Skip to content
Permalink
Browse files
Configurable opts for babel-preset-env + babel-plugin-transform-runti…
…me (#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
  • Loading branch information
tmcw authored and timneutkens committed Oct 7, 2017
1 parent a761aa5 commit 559c25253ea4a50fbc04ef37f466d9e9b616512a
Showing 4 changed files with 65 additions and 4 deletions.
@@ -0,0 +1,26 @@
{
"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
}
}]
]
}
}
}
@@ -0,0 +1,12 @@
{
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^15.4.2",
"react-dom": "^15.4.2"
}
}
@@ -0,0 +1,21 @@
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 = {

const plugins = envPlugins[process.env.NODE_ENV] || envPlugins['development']

module.exports = {
module.exports = (context, opts = {}) => ({
presets: [
[require.resolve('babel-preset-env'), {
modules: false
modules: false,
...opts['preset-env']
}],
require.resolve('babel-preset-react')
],
@@ -23,7 +24,8 @@ module.exports = {
require.resolve('./plugins/handle-import'),
require.resolve('babel-plugin-transform-object-rest-spread'),
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'),
...plugins,
[
@@ -43,4 +45,4 @@ module.exports = {
}
]
]
}
})

0 comments on commit 559c252

Please sign in to comment.