Netlify-cms: Add necessary polyfills to support transpiled features.

Created on 16 Oct 2017  路  8Comments  路  Source: netlify/netlify-cms

We transpile our JS code, but it doesn't necessarily support everything (see https://babeljs.io/docs/usage/caveats/). When babel-preset-env v7 is released, we can use useBuiltIns: "usage" to automatically add any polyfills needed after transpilation.

browser-compatibility intermediate bug chore accepted stale

Most helpful comment

I also think we should remove the stage-* presets and use the specific plugins we want directly.

All 8 comments

We can also remove the browser targets from the .babelrc, when we upgrade to v7, because they added support for using the browserslist in package.json.

I also think we should remove the stage-* presets and use the specific plugins we want directly.

Babel 7 also affects the transform-runtime plugin: useBuiltIns is added, which means we can stop using polyfilled Map, Symbol, etc, by setting it to true.

EDIT: Actually the new useBuiltIns: "usage" setting in the ENV preset is the same as that part of transform-runtime, so we would want to have both settings on, which turns the transform-runtime one off, and leaves the ENV one on.

EDIT: Actually, they're not exactly the same. The ENV one pulls in only the polyfills that are needed for the supported browsers, but it adds them to the global scope. Transform-runtime adds them for everything, even when supported, but only adds them to the module scope. See https://github.com/babel/babel/issues/7267 for details.

If the discussion in https://github.com/babel/babel/issues/6628 takes off, that would be nice.

Just did some testing with Babel v7.0.0-beta.38. transform-runtime has the benefit of not polluting the global scope, but IMO it's not the most maintainable/minimal option, since it polyfills everything, even if the browser supports it.

I propose that we do:

["@babel/preset-env", {
  "modules": false,
  "useBuiltIns": "usage" // Add necessary polyfills to the global scope.
}]

Only use the runtime transform for helpers. We probably don't really need this anyway -- we're not transpiling much anyway with only the last 2 versions of browsers -- so it probably won't really change size.

["@babel/plugin-transform-runtime", {
  "helpers": true,
  "useBuiltIns": true,
  "useESModules": true,
  "polyfill": false,
  "regenerator": false
}]

I'm with that.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Closing this as outdated. Please re-open if necessary.

Was this page helpful?
0 / 5 - 0 ratings