Skip to content

Commit 0809fc8

Browse files
feat(babel-preset-app): pass full config to @babel/preset-env (vuejs#5522)
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 vuejs#5208
1 parent 34f303b commit 0809fc8

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,18 @@ test('should inject polyfills / helpers using "import" statements for an es modu
209209
expect(code).toMatch('import "core-js/modules/es.promise"')
210210
expect(code).not.toMatch('require(')
211211
})
212+
213+
test('should not inject excluded polyfills', () => {
214+
const { code } = babel.transformSync(`
215+
new Promise()
216+
`.trim(), {
217+
babelrc: false,
218+
presets: [[preset, {
219+
exclude: ['es.promise'],
220+
polyfills: ['es.array.iterator', 'es.object.assign']
221+
}]],
222+
filename: 'test-entry-file.js'
223+
})
224+
225+
expect(code).not.toMatch('es.promise')
226+
})

packages/@vue/babel-preset-app/index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,7 @@ module.exports = (context, options = {}) => {
246246
// https://github.com/babel/babel/issues/9903
247247
include: [/@babel[\/|\\\\]runtime/],
248248
presets: [
249-
[require('@babel/preset-env'), {
250-
useBuiltIns,
251-
corejs: useBuiltIns ? require('core-js/package.json').version : false
252-
}]
249+
[require('@babel/preset-env'), envOptions]
253250
]
254251
}]
255252
}

0 commit comments

Comments
 (0)