From c1b8b921f119cb37a940971b1352e06096bd9aee Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 30 Dec 2024 19:38:22 +0000 Subject: [PATCH] perf(rspack,webpack): drop `lodash-es` dependency (#30409) --- packages/kit/src/template.ts | 4 ++-- packages/rspack/package.json | 2 -- packages/webpack/package.json | 2 -- packages/webpack/src/presets/base.ts | 5 +++-- packages/webpack/src/utils/config.ts | 7 ------- packages/webpack/src/webpack.ts | 4 ++-- pnpm-lock.yaml | 29 ---------------------------- 7 files changed, 7 insertions(+), 46 deletions(-) diff --git a/packages/kit/src/template.ts b/packages/kit/src/template.ts index ccaf936f6c..d471a7c1eb 100644 --- a/packages/kit/src/template.ts +++ b/packages/kit/src/template.ts @@ -14,7 +14,7 @@ import { tryUseNuxt, useNuxt } from './context' import { resolveNuxtModule } from './resolve' /** - * Renders given template using lodash template during build into the project buildDir + * Renders given template during build into the virtual file system (and optionally to disk in the project `buildDir`) */ export function addTemplate (_template: NuxtTemplate | string) { const nuxt = useNuxt() @@ -44,7 +44,7 @@ export function addServerTemplate (template: NuxtServerTemplate) { } /** - * Renders given types using lodash template during build into the project buildDir + * Renders given types during build to disk in the project `buildDir` * and register them as types. */ export function addTypeTemplate (_template: NuxtTypeTemplate) { diff --git a/packages/rspack/package.json b/packages/rspack/package.json index 23b3263c39..2839f3ed7b 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -46,7 +46,6 @@ "h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e", "jiti": "^2.4.2", "knitwork": "^1.2.0", - "lodash-es": "4.17.21", "magic-string": "^0.30.17", "memfs": "^4.15.1", "ohash": "^1.1.4", @@ -73,7 +72,6 @@ }, "devDependencies": { "@nuxt/schema": "workspace:*", - "@types/lodash-es": "4.17.12", "@types/pify": "5.0.4", "@types/webpack-bundle-analyzer": "4.7.0", "@types/webpack-hot-middleware": "2.25.9", diff --git a/packages/webpack/package.json b/packages/webpack/package.json index 401cdfc1e4..be2cf108f6 100644 --- a/packages/webpack/package.json +++ b/packages/webpack/package.json @@ -45,7 +45,6 @@ "h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e", "jiti": "^2.4.2", "knitwork": "^1.2.0", - "lodash-es": "4.17.21", "magic-string": "^0.30.17", "memfs": "^4.15.1", "mini-css-extract-plugin": "^2.9.2", @@ -75,7 +74,6 @@ "devDependencies": { "@nuxt/schema": "workspace:*", "@rspack/core": "1.1.8", - "@types/lodash-es": "4.17.12", "@types/pify": "5.0.4", "@types/webpack-bundle-analyzer": "4.7.0", "@types/webpack-hot-middleware": "2.25.9", diff --git a/packages/webpack/src/presets/base.ts b/packages/webpack/src/presets/base.ts index 1671f74ddc..4e80ea8c54 100644 --- a/packages/webpack/src/presets/base.ts +++ b/packages/webpack/src/presets/base.ts @@ -9,6 +9,7 @@ import escapeRegExp from 'escape-string-regexp' import { joinURL } from 'ufo' import type { NuxtOptions } from '@nuxt/schema' import { isTest } from 'std-env' +import { defu } from 'defu' import type { WarningFilter } from '../plugins/warning-ignore' import WarningIgnorePlugin from '../plugins/warning-ignore' import type { WebpackConfigContext } from '../utils/config' @@ -27,7 +28,7 @@ export async function base (ctx: WebpackConfigContext) { } function baseConfig (ctx: WebpackConfigContext) { - ctx.config = { + ctx.config = defu({}, { name: ctx.name, entry: { app: [resolve(ctx.options.appDir, ctx.options.experimental.asyncEntry ? 'entry.async' : 'entry')] }, module: { rules: [] }, @@ -45,7 +46,7 @@ function baseConfig (ctx: WebpackConfigContext) { output: getOutput(ctx), stats: statsMap[ctx.nuxt.options.logLevel] ?? statsMap.info, ...ctx.config, - } + } satisfies Configuration) } function basePlugins (ctx: WebpackConfigContext) { diff --git a/packages/webpack/src/utils/config.ts b/packages/webpack/src/utils/config.ts index 526d5b111c..f7f01570ed 100644 --- a/packages/webpack/src/utils/config.ts +++ b/packages/webpack/src/utils/config.ts @@ -1,7 +1,6 @@ import type { Configuration } from 'webpack' import type { Nuxt, NuxtOptions } from '@nuxt/schema' import { logger } from '@nuxt/kit' -import { cloneDeep } from 'lodash-es' import { toArray } from './index' export interface WebpackConfigContext { @@ -63,9 +62,3 @@ export function fileName (ctx: WebpackConfigContext, key: string) { return fileName } - -export function getWebpackConfig (ctx: WebpackConfigContext): Configuration { - // Clone to avoid leaking config between Client and Server - // TODO: rewrite webpack implementation to avoid necessity for this - return cloneDeep(ctx.config) -} diff --git a/packages/webpack/src/webpack.ts b/packages/webpack/src/webpack.ts index ccc8717031..e9beda3e3e 100644 --- a/packages/webpack/src/webpack.ts +++ b/packages/webpack/src/webpack.ts @@ -15,7 +15,7 @@ import { DynamicBasePlugin } from './plugins/dynamic-base' import { ChunkErrorPlugin } from './plugins/chunk' import { createMFS } from './utils/mfs' import { client, server } from './configs' -import { applyPresets, createWebpackConfigContext, getWebpackConfig } from './utils/config' +import { applyPresets, createWebpackConfigContext } from './utils/config' import { dynamicRequire } from './nitro/plugins/dynamic-require' import { builder, webpack } from '#builder' @@ -28,7 +28,7 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { const ctx = createWebpackConfigContext(nuxt) ctx.userConfig = defu(nuxt.options.webpack[`$${preset.name as 'client' | 'server'}`], ctx.userConfig) await applyPresets(ctx, preset) - return getWebpackConfig(ctx) + return ctx.config })) /** Inject rollup plugin for Nitro to handle dynamic imports from webpack chunks */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f54a273741..2398b305b6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -550,9 +550,6 @@ importers: knitwork: specifier: ^1.2.0 version: 1.2.0 - lodash-es: - specifier: 4.17.21 - version: 4.17.21 magic-string: specifier: ^0.30.17 version: 0.30.17 @@ -626,9 +623,6 @@ importers: '@nuxt/schema': specifier: workspace:* version: link:../schema - '@types/lodash-es': - specifier: 4.17.12 - version: 4.17.12 '@types/pify': specifier: 5.0.4 version: 5.0.4 @@ -949,9 +943,6 @@ importers: knitwork: specifier: ^1.2.0 version: 1.2.0 - lodash-es: - specifier: 4.17.21 - version: 4.17.21 magic-string: specifier: ^0.30.17 version: 0.30.17 @@ -1034,9 +1025,6 @@ importers: '@rspack/core': specifier: 1.1.8 version: 1.1.8 - '@types/lodash-es': - specifier: 4.17.12 - version: 4.17.12 '@types/pify': specifier: 5.0.4 version: 5.0.4 @@ -2620,12 +2608,6 @@ packages: '@types/json-schema@7.0.15': resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} - '@types/lodash-es@4.17.12': - resolution: {integrity: sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==} - - '@types/lodash@4.17.7': - resolution: {integrity: sha512-8wTvZawATi/lsmNu10/j2hk1KEP0IvjubqPE3cu1Xz7xfXXt5oCq3SNUz4fMIP4XGF9Ky+Ue2tBA3hcS7LSBlA==} - '@types/mdast@4.0.4': resolution: {integrity: sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==} @@ -5302,9 +5284,6 @@ packages: resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} engines: {node: '>=10'} - lodash-es@4.17.21: - resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==} - lodash.defaults@4.2.0: resolution: {integrity: sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==} @@ -9524,12 +9503,6 @@ snapshots: '@types/json-schema@7.0.15': {} - '@types/lodash-es@4.17.12': - dependencies: - '@types/lodash': 4.17.7 - - '@types/lodash@4.17.7': {} - '@types/mdast@4.0.4': dependencies: '@types/unist': 3.0.3 @@ -12763,8 +12736,6 @@ snapshots: dependencies: p-locate: 5.0.0 - lodash-es@4.17.21: {} - lodash.defaults@4.2.0: {} lodash.isarguments@3.1.0: {}