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

Option to disable polyfills through babel-preset-env #812

Closed
chrisvfritz opened this issue Feb 9, 2018 · 2 comments
Closed

Option to disable polyfills through babel-preset-env #812

chrisvfritz opened this issue Feb 9, 2018 · 2 comments

Comments

@chrisvfritz
Copy link
Contributor

What problem does this feature solve?

The @vue/app preset will always bundle any needed polyfills. An alternative to including polyfills via Babel is the polyfill.io service, which will only serve polyfills if the browser actually needs them, thus vastly reducing total bundle size for most visitors.

For users that want to use this service, could we provide an option to disable polyfills through babel-preset-env?

What does the proposed API look like?

I see a few solutions:

  • A: Simply document how to solve the problem in .babelrc if that's feasible without potentially breaking with the @vue/app preset.
  • B: Create a new preset called something like @vue/app-no-polyfills.
  • C: Provide an option in vue.config.js to disable polyfills.

I don't have a strong preference on which of those strategies is used.

@LinusBorg
Copy link
Member

LinusBorg commented Feb 9, 2018

I think piping the useBuiltInsoption through the vue-app preset to the preset env options should be easy enough and worth it.

https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/babel-preset-app/index.js#L20

should become

useBuiltIns: options.useBuiltIns || 'usage'

...and the option should be documented in README.

Then in .babelrc you can simply do:

{
  "presets": [
    ["@vue/app", { "useBuiltIns": false }]
  ]
}

It would also be possible to overwrite the preset-env settings in .babelrc, but explaining that would take more characters than adding the option I think :D

@chrisvfritz
Copy link
Contributor Author

@LinusBorg I like that. I'm wondering if taking it a step further would be even better though, e.g.:

{
  "presets": [
    ["@vue/app", { "bundlePolyfills": false }]
  ]
}

This way, the option basically explains itself and users don't have to know about the implementation detail of useBuiltIns. And, we also retain the freedom to change how we bundle polyfills in the future without it being a breaking change for users. What do you think?

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

No branches or pull requests

2 participants