From e295ae7ffd12d0d8e891cc6249ad475ed9c140d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ch=C5=82odnicki?= Date: Tue, 28 Jul 2020 14:33:15 +0200 Subject: [PATCH] fix: add types for `build.corejs` option and use number (#7789) --- .../cli/test/unit/__snapshots__/webpack.test.js.snap | 4 ++-- packages/types/config/build.d.ts | 1 + packages/webpack/src/config/base.js | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) 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'), {