From 0809fc8a9c5dc23d44c598d5138d756cac4bc0c5 Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Fri, 29 May 2020 15:06:23 +0200 Subject: [PATCH] feat(babel-preset-app): pass full config to @babel/preset-env (#5522) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass not just the useBuiltIns and corejs options, but the whole envOptions object, into the @babel/preset-env preset that is used to transform @babel/runtime, just like for the @babel/preset-env that is used for the application source code. This allows users to also specify other options, such as `exclude` and `polyfills`, and have them apply here too. In particular, this can be used to exclude the Promise polyfill, e. g. if Promise is already polyfilled in some other way. Previously, exclude: ['es.promise'], polyfills: ['es.array.iterator', 'es.object.assign'], could be used to configure the preset for the application source code, but the babel runtime would be transformed without those options, and so es.promise would still end up being included. Closes #5208 --- .../__tests__/babel-preset.spec.js | 15 +++++++++++++++ packages/@vue/babel-preset-app/index.js | 5 +---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js b/packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js index 1b2832f00f..f8090aa2f0 100644 --- a/packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js +++ b/packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js @@ -209,3 +209,18 @@ test('should inject polyfills / helpers using "import" statements for an es modu expect(code).toMatch('import "core-js/modules/es.promise"') expect(code).not.toMatch('require(') }) + +test('should not inject excluded polyfills', () => { + const { code } = babel.transformSync(` + new Promise() + `.trim(), { + babelrc: false, + presets: [[preset, { + exclude: ['es.promise'], + polyfills: ['es.array.iterator', 'es.object.assign'] + }]], + filename: 'test-entry-file.js' + }) + + expect(code).not.toMatch('es.promise') +}) diff --git a/packages/@vue/babel-preset-app/index.js b/packages/@vue/babel-preset-app/index.js index be8775f33e..207b645a4c 100644 --- a/packages/@vue/babel-preset-app/index.js +++ b/packages/@vue/babel-preset-app/index.js @@ -246,10 +246,7 @@ module.exports = (context, options = {}) => { // https://github.com/babel/babel/issues/9903 include: [/@babel[\/|\\\\]runtime/], presets: [ - [require('@babel/preset-env'), { - useBuiltIns, - corejs: useBuiltIns ? require('core-js/package.json').version : false - }] + [require('@babel/preset-env'), envOptions] ] }] }