mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
fix: auto transform and warning for @nuxtjs/babel-preset-app (#4297)
This commit is contained in:
parent
f5bf24ab83
commit
31ef70e560
@ -170,9 +170,32 @@ export function getNuxtConfig(_options) {
|
||||
options.build.cssSourceMap = options.dev
|
||||
}
|
||||
|
||||
const babelConfig = options.build.babel
|
||||
// babel cacheDirectory
|
||||
if (options.build.babel.cacheDirectory === undefined) {
|
||||
options.build.babel.cacheDirectory = options.dev
|
||||
if (babelConfig.cacheDirectory === undefined) {
|
||||
babelConfig.cacheDirectory = options.dev
|
||||
}
|
||||
|
||||
// TODO: remove this warn in Nuxt 3
|
||||
if (Array.isArray(babelConfig.presets)) {
|
||||
const warnPreset = (presetName) => {
|
||||
const oldPreset = '@nuxtjs/babel-preset-app'
|
||||
const newPreset = '@nuxt/babel-preset-app'
|
||||
if (presetName.includes(oldPreset)) {
|
||||
presetName = presetName.replace(oldPreset, newPreset)
|
||||
consola.warn('@nuxtjs/babel-preset-app has been deprecated, please use @nuxt/babel-preset-app.')
|
||||
}
|
||||
return presetName
|
||||
}
|
||||
babelConfig.presets = babelConfig.presets.map((preset) => {
|
||||
const hasOptions = Array.isArray(preset)
|
||||
if (hasOptions) {
|
||||
preset[0] = warnPreset(preset[0])
|
||||
} else if (typeof preset === 'string') {
|
||||
preset = warnPreset(preset)
|
||||
}
|
||||
return preset
|
||||
})
|
||||
}
|
||||
|
||||
// vue config
|
||||
|
@ -37,4 +37,28 @@ describe('basic config defaults', () => {
|
||||
options = getNuxtConfig({ globalName: 'foo?' })
|
||||
expect(options.globalName).toEqual('nuxt')
|
||||
})
|
||||
|
||||
test('@nuxtjs/babel-preset-app has been deprecated', () => {
|
||||
let options = getNuxtConfig({
|
||||
build: {
|
||||
babel: {
|
||||
presets: ['@nuxtjs/babel-preset-app']
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(options.build.babel.presets).toEqual(['@nuxt/babel-preset-app'])
|
||||
expect(consola.warn).toHaveBeenCalledWith('@nuxtjs/babel-preset-app has been deprecated, please use @nuxt/babel-preset-app.')
|
||||
|
||||
consola.warn.mockClear()
|
||||
|
||||
options = getNuxtConfig({
|
||||
build: {
|
||||
babel: {
|
||||
presets: [['@nuxtjs/babel-preset-app']]
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(options.build.babel.presets).toEqual([['@nuxt/babel-preset-app']])
|
||||
expect(consola.warn).toHaveBeenCalledWith('@nuxtjs/babel-preset-app has been deprecated, please use @nuxt/babel-preset-app.')
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user