mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
feat(webpack): extendable babel.presets
and babel envName
(#5637)
This commit is contained in:
parent
8576b4fcfd
commit
adb381275b
@ -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)
|
||||
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') {
|
||||
options.presets = options.presets({ isServer: this.isServer })
|
||||
options.presets = options.presets({ isServer: this.isServer }, defaultPreset)
|
||||
}
|
||||
|
||||
if (!options.babelrc && !options.presets) {
|
||||
options.presets = [
|
||||
[
|
||||
require.resolve('@nuxt/babel-preset-app'),
|
||||
{
|
||||
buildTarget: this.isServer ? 'server' : 'client'
|
||||
}
|
||||
]
|
||||
]
|
||||
options.presets = [ defaultPreset ]
|
||||
}
|
||||
|
||||
return options
|
||||
|
@ -1,4 +1,3 @@
|
||||
import clone from 'lodash/clone'
|
||||
import WebpackClientConfig from './client'
|
||||
|
||||
export default class WebpackModernConfig extends WebpackClientConfig {
|
||||
@ -15,17 +14,17 @@ export default class WebpackModernConfig extends WebpackClientConfig {
|
||||
}
|
||||
|
||||
getBabelOptions() {
|
||||
const options = clone(this.buildContext.buildOptions.babel)
|
||||
|
||||
options.presets = [
|
||||
[
|
||||
require.resolve('@nuxt/babel-preset-app'),
|
||||
{
|
||||
modern: true
|
||||
}
|
||||
return {
|
||||
...this.buildContext.buildOptions.babel,
|
||||
envName: this.name,
|
||||
presets: [
|
||||
[
|
||||
require.resolve('@nuxt/babel-preset-app'),
|
||||
{
|
||||
modern: true
|
||||
}
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
return options
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user