Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node 8 (async/await) #83

Closed
mxstbr opened this issue Sep 7, 2017 · 4 comments · Fixed by #87
Closed

Node 8 (async/await) #83

mxstbr opened this issue Sep 7, 2017 · 4 comments · Fixed by #87

Comments

@mxstbr
Copy link
Collaborator

mxstbr commented Sep 7, 2017

The backpack Babel preset does a bunch of stuff to make async/await supported in environments that don't support it:

[require.resolve('babel-plugin-transform-regenerator'), {
// Async functions are converted to generators by babel-preset-env (which
// is based on babel-preset-latest)
async: false
}],
// This is so we don't need to add `babel-polyfill` to our webpack `entry`.
// Unlike `babel-polyfill`, `babel-runtime` + the transform do not pollute
// the global namespace. Yay.
// @see https://medium.com/@jcse/clearing-up-the-babel-6-ecosystem-c7678a314bf3#.7j10g8yn0
[require.resolve('babel-plugin-transform-runtime'), {
helpers: false,
polyfill: false,
regenerator: true,
// Resolve the Babel runtime relative to the config.
moduleName: path.dirname(require.resolve('babel-runtime/package'))
}]

The issue is that as of the Node 8 LTS release it's totally unnecessary since it supports async/await out of the box! To get it to build with vanilla async/await (not transpiled to generators) I had to opt-out of the shared Babel config and basically just run with this .babelrc:

{
  "presets": [
    [
      "env",
      {
        "targets": {
          "node": "current"
        },
        "useBuiltIns": true,
        "exclude": [
          "babel-plugin-transform-regenerator",
          "transform-async-to-generator"
        ]
      }
    ]
  ],
  "plugins": [
    "transform-flow-strip-types",
    "transform-object-rest-spread",
    "babel-plugin-transform-react-jsx",
    "syntax-dynamic-import"
  ]
}

It'd be A+++ super awesome if backpack did the right thing™️ for Node 8 by default, i.e. didn't transpile generators at all and didn't include regenerator in the bundle. 😊

@jaredpalmer
Copy link
Owner

Very much agree

@jaredpalmer
Copy link
Owner

Definitely a breaking change though.

@mxstbr
Copy link
Collaborator Author

mxstbr commented Sep 7, 2017

Maybe we could use process.version to include things optionally if a user is on Node < 8?

@yoyo837
Copy link

yoyo837 commented Sep 13, 2017

It is best to be able to automatically sniff using a different configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants