diff --git a/vike/node/api/build.ts b/vike/node/api/build.ts index 98c2225712..a4afd0a9f3 100644 --- a/vike/node/api/build.ts +++ b/vike/node/api/build.ts @@ -1,11 +1,12 @@ export { build } import { prepareViteApiCall } from './prepareViteApiCall.js' -import { build as buildVite, createBuilder } from 'vite' +import { build as buildVite, version } from 'vite' import type { APIOptions } from './types.js' import assert from 'assert' import { isVikeCli } from '../cli/context.js' import { isPrerendering } from '../prerender/context.js' +import { assertVersion } from '../../utils/assertVersion.js' /** * Programmatically trigger `$ vike build` @@ -26,6 +27,8 @@ async function build(options: APIOptions = {}): Promise<{}> { // > We purposely don't start the pre-rendering in this `build()` function but in a Rollup hook instead. // > Rationale: https://github.com/vikejs/vike/issues/2123 if (vikeConfig.global.config.viteEnvironmentAPI) { + assertVersion('Vite', version, '6.0.0') + const { createBuilder } = await import('vite') const builder = await createBuilder(viteConfigEnhanced) await builder.buildApp() } else { diff --git a/vike/node/plugin/plugins/buildConfig.ts b/vike/node/plugin/plugins/buildConfig.ts index 00dff47707..b4e687cfe0 100644 --- a/vike/node/plugin/plugins/buildConfig.ts +++ b/vike/node/plugin/plugins/buildConfig.ts @@ -36,7 +36,7 @@ import { prependEntriesDir } from '../../shared/prependEntriesDir.js' import { getFilePathResolved } from '../shared/getFilePath.js' import { getConfigValueBuildTime } from '../../../shared/page-configs/getConfigValueBuildTime.js' import { getOutDirs, type OutDirs, resolveOutDir } from '../shared/getOutDirs.js' -import { viteIsSSR } from '../shared/viteIsSSR.js' +import { vite6IsSSR, viteIsSSR } from '../shared/viteIsSSR.js' // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build. const importMetaUrl: string = import.meta.url const require_ = createRequire(importMetaUrl) @@ -109,7 +109,7 @@ function buildConfig(): Plugin[] { order: 'pre', sequential: true, async handler(options, bundle) { - if (isSsrBuild || this.environment.name === 'ssr') { + if (isSsrBuild || vite6IsSSR(this)) { console.log('FIXING SERVER ASSETS') // Ideally we'd move dist/_temp_manifest.json to dist/server/client-assets.json instead of dist/assets.json // - But we can't because there is no guarentee whether dist/server/ is generated before or after dist/client/ (generating dist/server/ after dist/client/ erases dist/server/client-assets.json) diff --git a/vike/node/plugin/shared/viteIsSSR.ts b/vike/node/plugin/shared/viteIsSSR.ts index e996c0e4c3..8f2c7e8e01 100644 --- a/vike/node/plugin/shared/viteIsSSR.ts +++ b/vike/node/plugin/shared/viteIsSSR.ts @@ -2,12 +2,17 @@ import { assert } from '../../../utils/assert.js' import { isObject } from '../../../utils/isObject.js' export { viteIsSSR } +export { vite6IsSSR } export { viteIsSSR_options } function viteIsSSR(config: { build?: { ssr?: boolean | string } }): boolean { return !!config?.build?.ssr } +function vite6IsSSR(self: T): boolean { + return 'environment' in self && self.environment.name === 'ssr' +} + type Options = undefined | boolean | { ssr?: boolean } // https://github.com/vitejs/vite/discussions/5109#discussioncomment-1450726 function viteIsSSR_options(options: Options): boolean {