From 2f327580d211bc2393fcdf8db67161dd8bd16161 Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Fri, 29 Dec 2023 12:51:18 +0200 Subject: [PATCH 01/16] perf(nuxt): refactor Object.fromEntries --- packages/nuxt/src/head/runtime/components.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/head/runtime/components.ts b/packages/nuxt/src/head/runtime/components.ts index 37d1df42245c..b92d157285b6 100644 --- a/packages/nuxt/src/head/runtime/components.ts +++ b/packages/nuxt/src/head/runtime/components.ts @@ -12,7 +12,15 @@ import type { Target } from './types' -const removeUndefinedProps = (props: Props) => +const removeUndefinedProps = (props: Props) => { + const finalProps = Object.create(null) + for (const key in props) { + const value = props[key] + if (value !== undefined) { + filteredProps[key] = value; + } + } + Object.fromEntries(Object.entries(props).filter(([, value]) => value !== undefined)) const setupForUseMeta = (metaFactory: (props: Props, ctx: SetupContext) => Record, renderChild?: boolean) => (props: Props, ctx: SetupContext) => { From cfefc7563bc9a5ac8200a1955ac11597e343c128 Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Fri, 29 Dec 2023 12:53:57 +0200 Subject: [PATCH 02/16] chore: add return and remove fromEntries --- packages/nuxt/src/head/runtime/components.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/nuxt/src/head/runtime/components.ts b/packages/nuxt/src/head/runtime/components.ts index b92d157285b6..3ed7a1ee069c 100644 --- a/packages/nuxt/src/head/runtime/components.ts +++ b/packages/nuxt/src/head/runtime/components.ts @@ -13,15 +13,15 @@ import type { } from './types' const removeUndefinedProps = (props: Props) => { - const finalProps = Object.create(null) + const filteredProps = Object.create(null) for (const key in props) { const value = props[key] if (value !== undefined) { filteredProps[key] = value; } } - - Object.fromEntries(Object.entries(props).filter(([, value]) => value !== undefined)) + return filteredProps +} const setupForUseMeta = (metaFactory: (props: Props, ctx: SetupContext) => Record, renderChild?: boolean) => (props: Props, ctx: SetupContext) => { useHead(() => metaFactory({ ...removeUndefinedProps(props), ...ctx.attrs }, ctx)) From 017a668367fc281f6c18459b5be575ddb5d9c601 Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Wed, 3 Jan 2024 17:00:46 +0200 Subject: [PATCH 03/16] feat!: vite object.entries revamp !!MAY BREAK!! --- packages/vite/src/plugins/analyze.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/plugins/analyze.ts b/packages/vite/src/plugins/analyze.ts index aa71fe765d44..ca9072cb9c54 100644 --- a/packages/vite/src/plugins/analyze.ts +++ b/packages/vite/src/plugins/analyze.ts @@ -13,14 +13,27 @@ export function analyzePlugin (ctx: ViteBuildContext): Plugin[] { { name: 'nuxt:analyze-minify', async generateBundle (_opts, outputBundle) { - for (const [_bundleId, bundle] of Object.entries(outputBundle)) { + for (const key in outputBundle) { + const finalModules: Promise[] = [] + const bundle = outputBundle[key] if (bundle.type !== 'chunk') { continue } - const originalEntries = Object.entries(bundle.modules) - const minifiedEntries = await Promise.all(originalEntries.map(async ([moduleId, module]) => { + const originalEntries = bundle.modules + for (const moduleId in originalEntries) { + const module = originalEntries[moduleId] + finalModules.push( + (async () => { + const { code } = await transform(module.code || '', { minify: true }); + bundle.modules[moduleId]= { ...module, code } + })() + ) + } + + /*const minifiedEntries = await Promise.all(originalEntries.map(async ([moduleId, module]) => { const { code } = await transform(module.code || '', { minify: true }) return [moduleId, { ...module, code }] })) - bundle.modules = Object.fromEntries(minifiedEntries) + bundle.modules = Object.fromEntries(minifiedEntries)*/ + await Promise.all(finalModules) } } }, From 47655f7391390bcc7401583c174f7df384388259 Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Wed, 3 Jan 2024 17:04:13 +0200 Subject: [PATCH 04/16] Update analyze.ts --- packages/vite/src/plugins/analyze.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/plugins/analyze.ts b/packages/vite/src/plugins/analyze.ts index ca9072cb9c54..66f4e5981f48 100644 --- a/packages/vite/src/plugins/analyze.ts +++ b/packages/vite/src/plugins/analyze.ts @@ -22,8 +22,8 @@ export function analyzePlugin (ctx: ViteBuildContext): Plugin[] { const module = originalEntries[moduleId] finalModules.push( (async () => { - const { code } = await transform(module.code || '', { minify: true }); - bundle.modules[moduleId]= { ...module, code } + const { code } = await transform(module.code || '', { minify: true }) + bundle.modules[moduleId] = { ...module, code } })() ) } From f62cb8d29f92dd53a4a446624478843a84daf730 Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Thu, 4 Jan 2024 11:52:43 +0200 Subject: [PATCH 05/16] Update nitro for object --- packages/nuxt/src/core/nitro.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 8303c4fee7b1..66b507991d37 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -260,16 +260,17 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { const _routeRules = nitro.options.routeRules for (const key in _routeRules) { if (key === '/__nuxt_error') { continue } - const filteredRules = Object.entries(_routeRules[key]) - .filter(([key, value]) => ['prerender', 'redirect'].includes(key) && value) - .map(([key, value]: any) => { - if (key === 'redirect') { - return [key, typeof value === 'string' ? value : value.to] - } - return [key, value] - }) - if (filteredRules.length > 0) { - routeRules[key] = Object.fromEntries(filteredRules) + let rulesNum: Number = 0 + const filteredRules = Object.create(null) + for (const routeKey in _routeRules[key]) { + const value = _routeRules[key][routeKey] + if (['prerender', 'redirect'].includes(routeKey) && value) { + filteredRules[routeKey] = routeKey === 'redirect' ? typeof value === 'string' ? value : value.to : value + rulesNum++ + } + } + if (rulesNum > 0) { + routeRules[key] = filteredRules } } From 2b1c18b098383902117e19333a5d558b276ac4ab Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Thu, 4 Jan 2024 13:17:32 +0200 Subject: [PATCH 06/16] chore: fix types --- packages/nuxt/src/core/nitro.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 66b507991d37..0e512349fab8 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -260,7 +260,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { const _routeRules = nitro.options.routeRules for (const key in _routeRules) { if (key === '/__nuxt_error') { continue } - let rulesNum: Number = 0 + let rulesNum = 0 const filteredRules = Object.create(null) for (const routeKey in _routeRules[key]) { const value = _routeRules[key][routeKey] From 6a31413fb43978e240780c25e91ed1943a6420f5 Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Thu, 4 Jan 2024 13:28:45 +0200 Subject: [PATCH 07/16] Update nitro.ts --- packages/nuxt/src/core/nitro.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 0e512349fab8..fa09b218427f 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -263,7 +263,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { let rulesNum = 0 const filteredRules = Object.create(null) for (const routeKey in _routeRules[key]) { - const value = _routeRules[key][routeKey] + const value = (_routeRules as any)[key][routeKey] if (['prerender', 'redirect'].includes(routeKey) && value) { filteredRules[routeKey] = routeKey === 'redirect' ? typeof value === 'string' ? value : value.to : value rulesNum++ From bbb8996925ce56ceb66b48731f958fb45933d579 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 4 Jan 2024 18:28:01 +0000 Subject: [PATCH 08/16] [autofix.ci] apply automated fixes --- test/bundle.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bundle.test.ts b/test/bundle.test.ts index 52001efcead1..4218ed8b83b8 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -72,7 +72,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM const serverDir = join(rootDir, '.output-inline/server') const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) - expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"515k"`) + expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"516k"`) const modules = await analyzeSizes('node_modules/**/*', serverDir) expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"77.0k"') From a4b86af4fe8d0cb69ad9879d3304d3c8f6e128bb Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Thu, 4 Jan 2024 20:31:44 +0200 Subject: [PATCH 09/16] object.fromentries --- packages/vite/src/vite.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index a4ce67b19028..f858f703f98b 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -51,6 +51,11 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { const { $client, $server, ...viteConfig } = nuxt.options.vite + const toReplace = Object.create(null) + for(const d of [';', '(', '{', '}', ' ', '\t', '\n']){ + toReplace[`${d}global.`]=`${d}globalThis.` + } + const ctx: ViteBuildContext = { nuxt, entry, @@ -104,7 +109,7 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { composables: nuxt.options.optimization.keyedComposables }), replace({ - ...Object.fromEntries([';', '(', '{', '}', ' ', '\t', '\n'].map(d => [`${d}global.`, `${d}globalThis.`])), + ...toReplace, preventAssignment: true }), virtual(nuxt.vfs) From 58105aba3ba763fba3ddbf2a371a65ee9bfeba23 Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Thu, 4 Jan 2024 20:32:29 +0200 Subject: [PATCH 10/16] chore: lint --- packages/vite/src/vite.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index f858f703f98b..9f439d3ee15d 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -52,8 +52,8 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { const { $client, $server, ...viteConfig } = nuxt.options.vite const toReplace = Object.create(null) - for(const d of [';', '(', '{', '}', ' ', '\t', '\n']){ - toReplace[`${d}global.`]=`${d}globalThis.` + for (const d of [';', '(', '{', '}', ' ', '\t', '\n']) { + toReplace[`${d}global.`] = `${d}globalThis.` } const ctx: ViteBuildContext = { From 00e424844007aa61caf12e0440fe0b30ddab1f27 Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Thu, 4 Jan 2024 20:41:37 +0200 Subject: [PATCH 11/16] composable object.fromEntries --- packages/vite/src/plugins/composable-keys.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/plugins/composable-keys.ts b/packages/vite/src/plugins/composable-keys.ts index 1a46b3d2d105..7dabfd6fedf6 100644 --- a/packages/vite/src/plugins/composable-keys.ts +++ b/packages/vite/src/plugins/composable-keys.ts @@ -22,7 +22,10 @@ const NUXT_LIB_RE = /node_modules\/(nuxt|nuxt3|nuxt-nightly)\// const SUPPORTED_EXT_RE = /\.(m?[jt]sx?|vue)/ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptions) => { - const composableMeta = Object.fromEntries(options.composables.map(({ name, ...meta }) => [name, meta])) + const composableMeta = options.composables.reduce((acc, { name, ...meta }) => { + acc[name] = meta + return acc + }, Object.create(null)) const maxLength = Math.max(...options.composables.map(({ argumentLength }) => argumentLength)) const keyedFunctions = new Set(options.composables.map(({ name }) => name)) From a138fca4b52c58b589b14c4e53e14c64f3df896c Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Thu, 4 Jan 2024 20:49:12 +0200 Subject: [PATCH 12/16] template object.fromentries --- packages/nuxt/src/core/templates.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index 3ce3c868b3f6..a378707d2009 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -155,7 +155,12 @@ export const schemaTemplate: NuxtTemplate = { const relativeRoot = relative(resolve(nuxt.options.buildDir, 'types'), nuxt.options.rootDir) const getImportName = (name: string) => (name[0] === '.' ? './' + join(relativeRoot, name) : name).replace(/\.\w+$/, '') const modules = moduleInfo.map(meta => [genString(meta.configKey), getImportName(meta.importName)]) - + const privateRuntimeConfig = Object.create(null) + for (const key in nuxt.options.runtimeConfig) { + if (key !== 'public') { + privateRuntimeConfig[key] = nuxt.options.runtimeConfig[key] + } + } return [ "import { NuxtModule, RuntimeConfig } from 'nuxt/schema'", "declare module 'nuxt/schema' {", @@ -165,7 +170,7 @@ export const schemaTemplate: NuxtTemplate = { ), modules.length > 0 ? ` modules?: (undefined | null | false | NuxtModule | string | [NuxtModule | string, Record] | ${modules.map(([configKey, importName]) => `[${genString(importName)}, Exclude]`).join(' | ')})[],` : '', ' }', - generateTypes(await resolveSchema(Object.fromEntries(Object.entries(nuxt.options.runtimeConfig).filter(([key]) => key !== 'public')) as Record), + generateTypes(await resolveSchema(privateRuntimeConfig as Record), { interfaceName: 'RuntimeConfig', addExport: false, From 2b77de6b9af07be11b98a16edb904f84c2975e96 Mon Sep 17 00:00:00 2001 From: Michael Brevard Date: Thu, 4 Jan 2024 20:55:30 +0200 Subject: [PATCH 13/16] layer-aliasing object.fromentries --- packages/nuxt/src/core/plugins/layer-aliasing.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/nuxt/src/core/plugins/layer-aliasing.ts b/packages/nuxt/src/core/plugins/layer-aliasing.ts index 52dc8bf2bed1..18f4160cc97a 100644 --- a/packages/nuxt/src/core/plugins/layer-aliasing.ts +++ b/packages/nuxt/src/core/plugins/layer-aliasing.ts @@ -17,12 +17,12 @@ const ALIAS_RE = /(?<=['"])[~@]{1,2}(?=\/)/g const ALIAS_RE_SINGLE = /(?<=['"])[~@]{1,2}(?=\/)/ export const LayerAliasingPlugin = createUnplugin((options: LayerAliasingOptions) => { - const aliases = Object.fromEntries(options.layers.map((l) => { + const aliases = options.layers.reduce((acc, l) => { const srcDir = l.config.srcDir || l.cwd const rootDir = l.config.rootDir || l.cwd const publicDir = join(srcDir, l.config?.dir?.public || 'public') - return [srcDir, { + acc[srcDir] = { aliases: { '~': l.config?.alias?.['~'] || srcDir, '@': l.config?.alias?.['@'] || srcDir, @@ -31,8 +31,9 @@ export const LayerAliasingPlugin = createUnplugin((options: LayerAliasingOptions }, prefix: relative(options.root, publicDir), publicDir: !options.dev && existsSync(publicDir) && publicDir - }] - })) + } + return acc + }, Object.create(null)) const layers = Object.keys(aliases).sort((a, b) => b.length - a.length) return { From 17387d3419fb5c37c669d34e92e6488733141c42 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 5 Jan 2024 15:29:48 +0000 Subject: [PATCH 14/16] refactor: avoid reduce --- .../nuxt/src/core/plugins/layer-aliasing.ts | 22 +++++++++---------- packages/vite/src/plugins/composable-keys.ts | 8 +++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/nuxt/src/core/plugins/layer-aliasing.ts b/packages/nuxt/src/core/plugins/layer-aliasing.ts index 18f4160cc97a..f73f67297f09 100644 --- a/packages/nuxt/src/core/plugins/layer-aliasing.ts +++ b/packages/nuxt/src/core/plugins/layer-aliasing.ts @@ -17,23 +17,23 @@ const ALIAS_RE = /(?<=['"])[~@]{1,2}(?=\/)/g const ALIAS_RE_SINGLE = /(?<=['"])[~@]{1,2}(?=\/)/ export const LayerAliasingPlugin = createUnplugin((options: LayerAliasingOptions) => { - const aliases = options.layers.reduce((acc, l) => { - const srcDir = l.config.srcDir || l.cwd - const rootDir = l.config.rootDir || l.cwd - const publicDir = join(srcDir, l.config?.dir?.public || 'public') + const aliases: Record, prefix: string, publicDir: false | string }> = {} + for (const layer of options.layers) { + const srcDir = layer.config.srcDir || layer.cwd + const rootDir = layer.config.rootDir || layer.cwd + const publicDir = join(srcDir, layer.config?.dir?.public || 'public') - acc[srcDir] = { + aliases[srcDir] = { aliases: { - '~': l.config?.alias?.['~'] || srcDir, - '@': l.config?.alias?.['@'] || srcDir, - '~~': l.config?.alias?.['~~'] || rootDir, - '@@': l.config?.alias?.['@@'] || rootDir + '~': layer.config?.alias?.['~'] || srcDir, + '@': layer.config?.alias?.['@'] || srcDir, + '~~': layer.config?.alias?.['~~'] || rootDir, + '@@': layer.config?.alias?.['@@'] || rootDir }, prefix: relative(options.root, publicDir), publicDir: !options.dev && existsSync(publicDir) && publicDir } - return acc - }, Object.create(null)) + } const layers = Object.keys(aliases).sort((a, b) => b.length - a.length) return { diff --git a/packages/vite/src/plugins/composable-keys.ts b/packages/vite/src/plugins/composable-keys.ts index 7dabfd6fedf6..a160545b598c 100644 --- a/packages/vite/src/plugins/composable-keys.ts +++ b/packages/vite/src/plugins/composable-keys.ts @@ -22,10 +22,10 @@ const NUXT_LIB_RE = /node_modules\/(nuxt|nuxt3|nuxt-nightly)\// const SUPPORTED_EXT_RE = /\.(m?[jt]sx?|vue)/ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptions) => { - const composableMeta = options.composables.reduce((acc, { name, ...meta }) => { - acc[name] = meta - return acc - }, Object.create(null)) + const composableMeta: Record = {} + for (const { name, ...meta } of options.composables) { + composableMeta[name] = meta + } const maxLength = Math.max(...options.composables.map(({ argumentLength }) => argumentLength)) const keyedFunctions = new Set(options.composables.map(({ name }) => name)) From 3f0bbb5db12b9f466fbb5f29c2b633a34fcaab1f Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 8 Jan 2024 13:55:49 +0000 Subject: [PATCH 15/16] refactor: use boolean --- packages/nuxt/src/core/nitro.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index fa09b218427f..a294eb335d6e 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -260,16 +260,16 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { const _routeRules = nitro.options.routeRules for (const key in _routeRules) { if (key === '/__nuxt_error') { continue } - let rulesNum = 0 - const filteredRules = Object.create(null) + let hasRules = false + const filteredRules = {} as Record for (const routeKey in _routeRules[key]) { const value = (_routeRules as any)[key][routeKey] if (['prerender', 'redirect'].includes(routeKey) && value) { filteredRules[routeKey] = routeKey === 'redirect' ? typeof value === 'string' ? value : value.to : value - rulesNum++ + hasRules = true } } - if (rulesNum > 0) { + if (hasRules) { routeRules[key] = filteredRules } } From 2bc6e86cebb7971e8449b792d35c2438a18b93b7 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 8 Jan 2024 14:07:17 +0000 Subject: [PATCH 16/16] chore: revert less significant instances --- packages/vite/src/plugins/analyze.ts | 21 ++++----------------- packages/vite/src/vite.ts | 7 +------ 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/packages/vite/src/plugins/analyze.ts b/packages/vite/src/plugins/analyze.ts index 66f4e5981f48..aa71fe765d44 100644 --- a/packages/vite/src/plugins/analyze.ts +++ b/packages/vite/src/plugins/analyze.ts @@ -13,27 +13,14 @@ export function analyzePlugin (ctx: ViteBuildContext): Plugin[] { { name: 'nuxt:analyze-minify', async generateBundle (_opts, outputBundle) { - for (const key in outputBundle) { - const finalModules: Promise[] = [] - const bundle = outputBundle[key] + for (const [_bundleId, bundle] of Object.entries(outputBundle)) { if (bundle.type !== 'chunk') { continue } - const originalEntries = bundle.modules - for (const moduleId in originalEntries) { - const module = originalEntries[moduleId] - finalModules.push( - (async () => { - const { code } = await transform(module.code || '', { minify: true }) - bundle.modules[moduleId] = { ...module, code } - })() - ) - } - - /*const minifiedEntries = await Promise.all(originalEntries.map(async ([moduleId, module]) => { + const originalEntries = Object.entries(bundle.modules) + const minifiedEntries = await Promise.all(originalEntries.map(async ([moduleId, module]) => { const { code } = await transform(module.code || '', { minify: true }) return [moduleId, { ...module, code }] })) - bundle.modules = Object.fromEntries(minifiedEntries)*/ - await Promise.all(finalModules) + bundle.modules = Object.fromEntries(minifiedEntries) } } }, diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index 9f439d3ee15d..a4ce67b19028 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -51,11 +51,6 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { const { $client, $server, ...viteConfig } = nuxt.options.vite - const toReplace = Object.create(null) - for (const d of [';', '(', '{', '}', ' ', '\t', '\n']) { - toReplace[`${d}global.`] = `${d}globalThis.` - } - const ctx: ViteBuildContext = { nuxt, entry, @@ -109,7 +104,7 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { composables: nuxt.options.optimization.keyedComposables }), replace({ - ...toReplace, + ...Object.fromEntries([';', '(', '{', '}', ' ', '\t', '\n'].map(d => [`${d}global.`, `${d}globalThis.`])), preventAssignment: true }), virtual(nuxt.vfs)