diff --git a/vike/node/plugin/plugins/serverEntryPlugin.ts b/vike/node/plugin/plugins/serverEntryPlugin.ts index 13c4cb7613..ec477dae82 100644 --- a/vike/node/plugin/plugins/serverEntryPlugin.ts +++ b/vike/node/plugin/plugins/serverEntryPlugin.ts @@ -4,6 +4,7 @@ import type { Plugin } from 'vite' import type { ConfigVikeUserProvided } from '../../../shared/ConfigVike.js' import { getGlobalObject } from '../utils.js' import { standalonePlugin } from './standalonePlugin.js' +import path from 'path' const globalObject = getGlobalObject('serverEntryPlugin.ts', { serverEntry: '' @@ -19,6 +20,7 @@ function serverEntryPlugin(configVike?: ConfigVikeUserProvided): Plugin[] { return [] } globalObject.serverEntry = serverEntry + let root = '' const serverEntryProdPlugin = (): Plugin => { return { @@ -34,8 +36,20 @@ function serverEntryPlugin(configVike?: ConfigVikeUserProvided): Plugin[] { rollupOptions: { input: { index: serverEntry } } + }, + vitePluginImportBuild: { + _disableAutoImporter: true } } + }, + configResolved(config) { + root = config.root + }, + renderChunk(code, chunk) { + if (chunk.facadeModuleId === path.posix.join(root, serverEntry)) { + code = "import './importBuild.cjs'\n" + code + } + return code } } } diff --git a/vike/node/plugin/plugins/standalonePlugin.ts b/vike/node/plugin/plugins/standalonePlugin.ts index 29687fb047..dc0e7507a7 100644 --- a/vike/node/plugin/plugins/standalonePlugin.ts +++ b/vike/node/plugin/plugins/standalonePlugin.ts @@ -43,9 +43,6 @@ function standalonePlugin({ serverEntry }: { serverEntry: string }): Plugin { // ../../node_modules/@brillout/picocolors/package.json:10:2: // 10 │ "sideEffects": false, noExternal: ['@brillout/picocolors'] - }, - vitePluginImportBuild: { - _disableAutoImporter: true } } }, @@ -64,7 +61,6 @@ function standalonePlugin({ serverEntry }: { serverEntry: string }): Plugin { renderChunk(code, chunk) { if (chunk.facadeModuleId === path.posix.join(root, serverEntry)) { - code = "import './importBuild.cjs'\n" + code builtEntryAbs = path.posix.join(outDirAbs, chunk.fileName) } return code