Skip to content

Commit

Permalink
fix(realtime): update logic for including sseLink
Browse files Browse the repository at this point in the history
  • Loading branch information
redwood-bot committed Feb 16, 2024
1 parent ad493cd commit ca004ef
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from 'fs'
import fs from 'fs'
import path from 'path'

import react from '@vitejs/plugin-react'
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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(
'</head>',
// @NOTE the slash in front, for windows compatibility and for pages in subdirectories
Expand All @@ -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 {
Expand Down Expand Up @@ -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/,
Expand Down

0 comments on commit ca004ef

Please sign in to comment.