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 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
|
||||||
|
@ -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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user