Skip to content

Commit

Permalink
fix: support Vite 3 and latest vite-plugin-ssr version
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Aug 24, 2022
1 parent c95ad76 commit 0a75971
Show file tree
Hide file tree
Showing 18 changed files with 562 additions and 110 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules/
/deps/
.pnpm-debug.log
6 changes: 3 additions & 3 deletions examples/vite-plugin-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"scripts": {
"dev": "npm run server",
"prod": "npm run build && npm run server:prod",
"build": "vite build && vite build --ssr",
"build": "vite build",
"server": "node ./server",
"server:prod": "cross-env NODE_ENV=production node ./server"
},
Expand All @@ -13,7 +13,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"telefunc": "0.1.24",
"vite": "2.6.7",
"vite-plugin-ssr": "^0.3.26"
"vite": "^3.0.9",
"vite-plugin-ssr": "^0.4.26"
}
}
8 changes: 3 additions & 5 deletions examples/vite-plugin-ssr/renderer/_default.page.client.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
export { render }

import ReactDOM from 'react-dom'
import React from 'react'
import { getPage } from 'vite-plugin-ssr/client'

hydrate()

async function hydrate() {
const pageContext = await getPage()
function render(pageContext) {
const { Page, pageProps } = pageContext
ReactDOM.hydrate(<Page {...pageProps} />, document.getElementById('page-view'))
// For `../.testRun.ts`
Expand Down
10 changes: 4 additions & 6 deletions examples/vite-plugin-ssr/server/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const express = require('express')
const { createPageRenderer } = require('vite-plugin-ssr')
const { renderPage } = require('vite-plugin-ssr')
const { telefunc, provideTelefuncContext } = require('telefunc')

const isProduction = process.env.NODE_ENV === 'production'
Expand All @@ -17,7 +17,7 @@ async function startServer() {
const vite = require('vite')
viteDevServer = await vite.createServer({
root,
server: { middlewareMode: 'ssr' }
server: { middlewareMode: true }
})
app.use(viteDevServer.middlewares)
}
Expand All @@ -39,12 +39,10 @@ async function startServer() {
res.status(statusCode).type(contentType).send(body)
})

const renderPage = createPageRenderer({ viteDevServer, isProduction, root })
app.get('*', async (req, res, next) => {
const { user, originalUrl: url } = req
const pageContextInit = {
user,
url
user: req.user,
urlOriginal: req.originalUrl
}
const pageContext = await renderPage(pageContextInit)
const { httpResponse } = pageContext
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
},
"dependencies": {
"@brillout/submodule-init": "0.1.2"
},
"devDependencies": {
"@brillout/dev-my-dep": "^0.0.9"
}
}

0 comments on commit 0a75971

Please sign in to comment.