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

View File

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