feat(webpack): extendable `babel.presets` and babel `envName` (#5637)

This commit is contained in:
Xin Du (Clark) 2019-05-06 15:00:07 +01:00 committed by Pooya Parsa
parent 8576b4fcfd
commit adb381275b
2 changed files with 28 additions and 23 deletions

View File

@ -1,7 +1,6 @@
import path from 'path' import path from 'path'
import consola from 'consola' import consola from 'consola'
import TimeFixPlugin from 'time-fix-plugin' import TimeFixPlugin from 'time-fix-plugin'
import clone from 'lodash/clone'
import cloneDeep from 'lodash/cloneDeep' import cloneDeep from 'lodash/cloneDeep'
import escapeRegExp from 'lodash/escapeRegExp' import escapeRegExp from 'lodash/escapeRegExp'
import VueLoader from 'vue-loader' import VueLoader from 'vue-loader'
@ -70,21 +69,28 @@ export default class WebpackBaseConfig {
} }
getBabelOptions() { getBabelOptions() {
const options = clone(this.buildContext.buildOptions.babel) const options = {
...this.buildContext.buildOptions.babel,
envName: this.name
}
if (options.configFile !== false) {
return options
}
const defaultPreset = [
require.resolve('@nuxt/babel-preset-app'),
{
buildTarget: this.isServer ? 'server' : 'client'
}
]
if (typeof options.presets === 'function') { if (typeof options.presets === 'function') {
options.presets = options.presets({ isServer: this.isServer }) options.presets = options.presets({ isServer: this.isServer }, defaultPreset)
} }
if (!options.babelrc && !options.presets) { if (!options.babelrc && !options.presets) {
options.presets = [ options.presets = [ defaultPreset ]
[
require.resolve('@nuxt/babel-preset-app'),
{
buildTarget: this.isServer ? 'server' : 'client'
}
]
]
} }
return options return options

View File

@ -1,4 +1,3 @@
import clone from 'lodash/clone'
import WebpackClientConfig from './client' import WebpackClientConfig from './client'
export default class WebpackModernConfig extends WebpackClientConfig { export default class WebpackModernConfig extends WebpackClientConfig {
@ -15,17 +14,17 @@ export default class WebpackModernConfig extends WebpackClientConfig {
} }
getBabelOptions() { getBabelOptions() {
const options = clone(this.buildContext.buildOptions.babel) return {
...this.buildContext.buildOptions.babel,
options.presets = [ envName: this.name,
[ presets: [
require.resolve('@nuxt/babel-preset-app'), [
{ require.resolve('@nuxt/babel-preset-app'),
modern: true {
} modern: true
}
]
] ]
] }
return options
} }
} }