diff --git a/packages/cli/test/unit/__snapshots__/webpack.test.js.snap b/packages/cli/test/unit/__snapshots__/webpack.test.js.snap index 0100e79fcf..719860577a 100644 --- a/packages/cli/test/unit/__snapshots__/webpack.test.js.snap +++ b/packages/cli/test/unit/__snapshots__/webpack.test.js.snap @@ -75,7 +75,7 @@ exports[`webpack nuxt webpack module.rules 1`] = ` \\"/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`] = ` \\"/packages/babel-preset-app/src/index.js\\", Object { \\"corejs\\": Object { - \\"version\\": \\"2\\", + \\"version\\": 2, }, }, ], diff --git a/packages/types/config/build.d.ts b/packages/types/config/build.d.ts index 3965c10c9e..617b5f594d 100644 --- a/packages/types/config/build.d.ts +++ b/packages/types/config/build.d.ts @@ -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 diff --git a/packages/webpack/src/config/base.js b/packages/webpack/src/config/base.js index fd092179e9..456bd8dee5 100644 --- a/packages/webpack/src/config/base.js +++ b/packages/webpack/src/config/base.js @@ -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'), {