diff --git a/packages/vite/src/client.ts b/packages/vite/src/client.ts index beb13de0c3..783ebf70b1 100644 --- a/packages/vite/src/client.ts +++ b/packages/vite/src/client.ts @@ -9,12 +9,10 @@ import { joinURL, withLeadingSlash, withoutLeadingSlash, withTrailingSlash } fro import escapeRE from 'escape-string-regexp' import defu from 'defu' import { cacheDirPlugin } from './plugins/cache-dir' -import { analyzePlugin } from './plugins/analyze' import { wpfs } from './utils/wpfs' import type { ViteBuildContext, ViteOptions } from './vite' import { writeManifest } from './manifest' import { devStyleSSRPlugin } from './plugins/dev-ssr-css' -import { viteNodePlugin } from './vite-node' export async function buildClient (ctx: ViteBuildContext) { const clientConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, { @@ -58,7 +56,9 @@ export async function buildClient (ctx: ViteBuildContext) { rootDir: ctx.nuxt.options.rootDir, buildAssetsURL: joinURL(ctx.nuxt.options.app.baseURL, ctx.nuxt.options.app.buildAssetsDir) }), - viteNodePlugin(ctx) + ctx.nuxt.options.experimental.viteNode + ? await import('./vite-node').then(r => r.viteNodePlugin(ctx)) + : undefined ], appType: 'custom', server: { @@ -87,7 +87,7 @@ export async function buildClient (ctx: ViteBuildContext) { // Add analyze plugin if needed if (ctx.nuxt.options.build.analyze) { - clientConfig.plugins.push(...analyzePlugin(ctx)) + clientConfig.plugins.push(...await import('./plugins/analyze').then(r => r.analyzePlugin(ctx))) } await ctx.nuxt.callHook('vite:extendConfig', clientConfig, { isClient: true, isServer: false }) diff --git a/packages/vite/src/dirs.ts b/packages/vite/src/dirs.ts index 6eacc10603..aac9cab1cc 100644 --- a/packages/vite/src/dirs.ts +++ b/packages/vite/src/dirs.ts @@ -1,5 +1,7 @@ import { fileURLToPath } from 'node:url' import { dirname, resolve } from 'pathe' -export const distDir = dirname(fileURLToPath(import.meta.url)) +let _distDir = dirname(fileURLToPath(import.meta.url)) +if (_distDir.endsWith('chunks')) { _distDir = dirname(_distDir) } +export const distDir = _distDir export const pkgDir = resolve(distDir, '..')