mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
refactor: improve babel preset (#4446)
This commit is contained in:
parent
d66e1ec896
commit
8baf574254
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user