Skip to content

Commit

Permalink
fix: workaround external require on ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 11, 2024
1 parent a282d91 commit 24a995f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
8 changes: 7 additions & 1 deletion packages/vite/src/node/server/environments/rolldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,15 @@ export class RolldownEnvironment extends DevEnvironment {
// `generate` should work but we use `write` so it's easier to see output and debug
const outputOptions: rolldown.OutputOptions = {
dir: this.outDir,
format: this.rolldownDevOptions.hmr ? 'app' : 'es',
format: this.rolldownDevOptions.hmr ? 'app' : 'esm',
// TODO: hmr_rebuild returns source map file when `sourcemap: true`
sourcemap: 'inline',
// TODO: https://github.com/rolldown/rolldown/issues/2041
// handle `require("stream")` in `react-dom/server`
banner:
this.name === 'ssr'
? `import __nodeModule from "node:module"; const require = __nodeModule.createRequire(import.meta.url);`
: undefined,
}
this.result = await this.instance.write(outputOptions)

Expand Down
3 changes: 0 additions & 3 deletions playground/rolldown-dev-ssr/src/ambient.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion playground/rolldown-dev-ssr/src/entry-server.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReactDOMServer from 'react-dom/server.browser'
import ReactDOMServer from 'react-dom/server'
import type { Connect } from 'vite'
import { App } from './app'

Expand Down
2 changes: 2 additions & 0 deletions playground/rolldown-dev-ssr/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { defineConfig } from 'vite'

process.setSourceMapsEnabled(true)

export default defineConfig({
environments: {
client: {
Expand Down

0 comments on commit 24a995f

Please sign in to comment.