fix: add types for build.corejs option and use number (#7789)

This commit is contained in:
Rafał Chłodnicki 2020-07-28 14:33:15 +02:00 committed by GitHub
parent 60f68638cb
commit e295ae7ffd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 7 deletions

View File

@ -75,7 +75,7 @@ exports[`webpack nuxt webpack module.rules 1`] = `
\\"<nuxtDir>/packages/babel-preset-app/src/index.js\\",
Object {
\\"corejs\\": Object {
\\"version\\": \\"2\\",
\\"version\\": 2,
},
},
],
@ -654,7 +654,7 @@ exports[`webpack nuxt webpack module.rules test=.jsx 1`] = `
\\"<nuxtDir>/packages/babel-preset-app/src/index.js\\",
Object {
\\"corejs\\": Object {
\\"version\\": \\"2\\",
\\"version\\": 2,
},
},
],

View File

@ -137,6 +137,7 @@ export interface NuxtOptionsBuild {
analyze?: BundleAnalyzerPlugin.Options | boolean
babel?: NuxtBabelOptions
cache?: boolean
corejs?: 'auto' | 2 | 3
crossorigin?: string
cssSourceMap?: boolean
devMiddleware?: WebpackDevMiddlewareOptions

View File

@ -120,15 +120,15 @@ export default class WebpackBaseConfig {
let corejsVersion = corejs
if (corejsVersion === 'auto') {
try {
corejsVersion = createRequire(rootDir)('core-js/package.json').version.split('.')[0]
corejsVersion = Number.parseInt(createRequire(rootDir)('core-js/package.json').version.split('.')[0])
} catch (_err) {
corejsVersion = '2'
corejsVersion = 2
}
}
if (corejsVersion !== '2' && corejsVersion !== '3') {
consola.warn(`Invalid corejs version ${JSON.stringify(corejsVersion)}! Please set "build.corejs" to either "2" or "3".`)
corejsVersion = '2'
if (![2, 3].includes(corejsVersion)) {
consola.warn(`Invalid corejs version ${corejsVersion}! Please set "build.corejs" to either "auto", 2 or 3.`)
corejsVersion = 2
}
const defaultPreset = [require.resolve('@nuxt/babel-preset-app'), {