diff --git a/packages/vite/src/index.ts b/packages/vite/src/index.ts index 4de0a64da24e..00d9f6f0a891 100644 --- a/packages/vite/src/index.ts +++ b/packages/vite/src/index.ts @@ -1,4 +1,4 @@ -import { existsSync } from 'fs' +import fs from 'fs' import path from 'path' import react from '@vitejs/plugin-react' @@ -30,6 +30,12 @@ export default function redwoodPluginVite(): PluginOption[] { const relativeEntryPath = path.relative(rwPaths.web.src, clientEntryPath) + // If realtime is enabled, we want to include the sseLink in the bundle. + // Right now the only way we have of telling is if the package is installed on the api side. + const realtimeEnabled = fs + .readFileSync(path.join(rwPaths.api.base, 'package.json'), 'utf-8') + .includes('@redwoodjs/realtime') + return [ { name: 'redwood-plugin-vite-html-env', @@ -83,7 +89,7 @@ export default function redwoodPluginVite(): PluginOption[] { // So we inject the entrypoint with the correct extension .tsx vs .jsx // And then inject the entry - if (existsSync(clientEntryPath)) { + if (fs.existsSync(clientEntryPath)) { return html.replace( '', // @NOTE the slash in front, for windows compatibility and for pages in subdirectories @@ -99,7 +105,7 @@ export default function redwoodPluginVite(): PluginOption[] { // but note index.html does not come through as an id during dev transform: (code: string, id: string) => { if ( - existsSync(clientEntryPath) && + fs.existsSync(clientEntryPath) && normalizePath(id) === normalizePath(rwPaths.web.html) ) { return { @@ -286,7 +292,7 @@ export default function redwoodPluginVite(): PluginOption[] { id: /@redwoodjs\/router\/dist\/splash-page/, }, ]), - !rwConfig.experimental.realtime.enabled && + !realtimeEnabled && removeFromBundle([ { id: /@redwoodjs\/web\/dist\/apollo\/sseLink/,