refactor: improve babel preset (#4446)

This commit is contained in:
Clark Du 2018-11-29 16:54:38 +00:00 committed by GitHub
parent d66e1ec896
commit 8baf574254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,5 @@
const path = require('path')
const defaultPolyfills = [
// Promise polyfill alone doesn't work in IE,
// Needs this as well. see: #1642
@ -37,14 +39,20 @@ module.exports = (context, options = {}) => {
const modern = !!options.modern
const {
polyfills: userPolyfills,
buildTarget,
loose = false,
useBuiltIns = (modern ? false : 'usage'),
debug = false,
useBuiltIns = 'usage',
modules = false,
polyfills: userPolyfills,
spec,
ignoreBrowserslistConfig = modern,
configPath,
include,
exclude,
shippedProposals,
forceAllTransforms,
decoratorsBeforeExport,
decoratorsLegacy
} = options
@ -69,25 +77,37 @@ module.exports = (context, options = {}) => {
// Pass options along to babel-preset-env
presets.push([
require('@babel/preset-env'), {
spec,
loose,
debug,
modules,
targets,
useBuiltIns,
forceAllTransforms,
ignoreBrowserslistConfig,
exclude: polyfills
configPath,
include,
exclude: polyfills.concat(exclude || []),
shippedProposals,
forceAllTransforms
}
])
plugins.push(
require('@babel/plugin-syntax-dynamic-import'),
[require('@babel/plugin-proposal-decorators'), { legacy: decoratorsLegacy !== false }],
[require('@babel/plugin-proposal-decorators'), {
decoratorsBeforeExport,
legacy: decoratorsLegacy !== false
}],
[require('@babel/plugin-proposal-class-properties'), { loose }]
)
// Transform runtime, but only for helpers
plugins.push([require('@babel/plugin-transform-runtime'), {
regenerator: useBuiltIns !== 'usage'
regenerator: useBuiltIns !== 'usage',
corejs: useBuiltIns !== false ? false : 2,
helpers: useBuiltIns === 'usage',
useESModules: true,
absoluteRuntime: path.dirname(require.resolve('@babel/runtime/package.json'))
}])
return {