UNPKG

vike

Version:

(Replaces Next.js/Nuxt) 🔨 Composable framework to build advanced applications with flexibility and stability.

50 lines (49 loc) • 2.01 kB
export { getServerConfig }; export { isUniversalDeployVitePreview }; import { catchAllEntry } from '@universal-deploy/store'; import { assert } from '../../../../utils/assert.js'; import '../../assertEnvVite.js'; function getServerConfig(vikeConfig) { let serverEntryId; let serverFilePath = null; let serverEntryVike; // universal-deploy support must be manually enabled const serverConfig = // +config.js > `export default { server: true }` vikeConfig.config.server || // +server.js exists !!vikeConfig._pageConfigGlobal.configValueSources.server || false; if (serverConfig === false) return; const serverPlusFile = vikeConfig._pageConfigGlobal.configValueSources.server?.[0]; if (serverPlusFile?.valueIsDefinedByPlusValueFile) { assert('filePathAbsoluteFilesystem' in serverPlusFile.definedAt); serverFilePath = serverPlusFile.definedAt.filePathAbsoluteFilesystem; assert(serverFilePath); serverEntryId = serverFilePath; serverEntryVike = serverFilePath; } else { serverEntryId = catchAllEntry; serverEntryVike = 'vike/fetch'; } return { // Used to filter which module ID to transform. // It points to a fully resolved server entry or the virtual universal-deploy catchAll entry. serverEntryId, // This entry will be pushed to universal-deploy via `addEntry`. // It either points to the default fetchable endpoint (vike/fetch), or one defined by the user through +server. serverEntryVike, serverFilePath, }; } function isUniversalDeployVitePreview(vikeConfig, viteConfigResolved) { const isServerConfig = getServerConfig(vikeConfig); if (!isServerConfig) return null; // not UD // @universal-deploy/node -> real preview // else -> vite preview const udNodePlugin = viteConfigResolved.plugins.find((p) => p.name.match(/^ud:node:(?!.*:disabled$)/)); return !udNodePlugin; }