Skip to content

Better polyfill default setting for @vue/babel-preset-app #1248

@LinusBorg

Description

@LinusBorg

What problem does this feature solve?

The current implementation of our bable preset sets the useBuiltIns option of the ``babel-preset-envpreset tousage`:

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

What that means it that only feature that babel comes across during transpilation are actually polyfilled.

The good

This is awesome since it keeps unnecessary polyfills out of our app

the bad

It's bad because any code in node_modules that relies on a poylfill requires the developer to manually inlcude this polyfill in i.e.main.js so it's picked up by babel. This is because we don't run /node_modules contents through babel, so the usage options doesn'T pick up the feature

The alternative

I think the current default is resulting in bad dev UX, because the dev has to know and understand about the way that usage works.

As an alternative, I propose to select entry as the defsault value for useBuiltIns.

The good

Now all features necessary for the targeted browsers will be polyfilled. That ensures that all code from /node_modules relying on a feature that we ourselves don't use will work nonetheless.

The bad

Unnecessary polyfills might be included. To allow the dev to optimize this, we could document how he could switch to usage polyfilling and what the implications are.

What does the proposed API look like?

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

-    useBuiltIns = 'usage',
+    useBuiltIns = 'entry',

https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/generator/template/src/main.js

+ import '@babel/polyfill'
import Vue from 'vue'
import App from './App.vue'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions