Skip to content

Commit

Permalink
feat(babel-preset-app): pass full config to @babel/preset-env (#5522)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lucaswerkmeister committed May 29, 2020
1 parent 34f303b commit 0809fc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 15 additions & 0 deletions packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js
Expand Up @@ -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')
})
5 changes: 1 addition & 4 deletions packages/@vue/babel-preset-app/index.js
Expand Up @@ -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]
]
}]
}
Expand Down

0 comments on commit 0809fc8

Please sign in to comment.