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

Unsure how usage-pure and transform-runtime should work #32

Closed
jquense opened this issue Aug 21, 2020 · 3 comments
Closed

Unsure how usage-pure and transform-runtime should work #32

jquense opened this issue Aug 21, 2020 · 3 comments

Comments

@jquense
Copy link
Contributor

jquense commented Aug 21, 2020

Sorry for the slew of issues, we are really testing out the work here (it's awesome!). The docs suggest that this can be used instead of corejs specific runtime packages:

{
  "presets": [
    ["@babel/preset-env", {
      "targets": { "firefox": 42 }
    }]
  ],
  "plugins": [
    ["@babel/transform-runtime", {
      "corejs": 3
    }]
  ]
}

It's unclear to me though how this would work for helpers that also need polyfills. like AsyncGenerator. Is this case supposed to be covered?

@nicolo-ribaudo
Copy link
Member

When designing these plugins, I decided to threat @babel/runtime as a normal dependency: you compile it if you need. Note that this wasn't possible in the past and caused recursion errors in the compiled output, but it's safe since Babel 7.8.4 it is safe.

I would thus configure Babel like this:

// babel.config.json
{
  "overrides": [{
    "test": "./src",
    "presets": [
      ["@babel/preset-env", {
        "targets": { "firefox": 42 }
      }]
    ],
    "plugins": [
      "@babel/transform-runtime"
    ]
  }, {
    "test": ["./src", "./node_modules/@babel/runtime"],
    "plugins": [
      ["polyfill-corejs3", {
        "method": "usage-pure",
        "targets": { "firefox": 42 }
      }]
    ]
  }]
}

@nicolo-ribaudo
Copy link
Member

Demo: https://github.com/nicolo-ribaudo/repro-babel-polyfills-32 (npm ci and ./node_modules/.bin/webpack)

@jquense
Copy link
Contributor Author

jquense commented Sep 1, 2020

sweet, makes sense 👍

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

No branches or pull requests

2 participants