-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change project to "type": "module" so we can use pure ESM dependencies #38
Conversation
import { dirname, resolve } from 'path' | ||
import { fileURLToPath } from 'url' | ||
import { createServer as createViteServer } from 'vite' | ||
|
||
const dir = dirname(fileURLToPath(import.meta.url)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are just to replace __dirname
, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#what-do-i-use-instead-of-__dirname-and-__filename
async function prerender () { | ||
const vite = await createViteServer({ | ||
server: { middlewareMode: 'ssr' } | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of these changes are mostly the same as before. We've just wrapped everything in an async function
so that we can create a Vite dev server...
}) | ||
|
||
try { | ||
const { Renderer } = await vite.ssrLoadModule('/src/entry-server.jsx') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... then use that dev server to access vite.ssrLoadModule
.
This is now more consistent with what's happening in our server.js
.
import express from 'express' | ||
import { createServer as createViteServer } from 'vite' | ||
|
||
const dir = dirname(fileURLToPath(import.meta.url)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, these changes are just to replace __dirname
https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#what-do-i-use-instead-of-__dirname-and-__filename
|
||
export default defineConfig({ | ||
plugins: config.plugins, | ||
plugins: [react(), mdx({ rehypePlugins: [rehypeSlug] })], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer need the extra vite.config.server.js
due to the changes in prerender.js
, so its config has moved in here.
Closes #28
Also allows upgrading from
vite-plugin-mdx
to@mdx-js/rollup
so we can get MDX 2