Skip to content

Commit

Permalink
RSC: Explain noExternal vite config option (#10429)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Apr 8, 2024
1 parent b379670 commit 47ef5d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/vite/src/rsc/rscBuildAnalyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export async function rscBuildAnalyze() {
),
],
ssr: {
// We can ignore everything that starts with `node:` because it's not
// going to be RSCs
// As of vite 5.2 `true` here means "all except node built-ins"
noExternal: true,
// TODO (RSC): Figure out what the `external` list should be. Right
// now it's just copied from waku, plus we added prisma
Expand Down
13 changes: 7 additions & 6 deletions packages/vite/src/rsc/rscBuildForServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,22 @@ export async function rscBuildForServer(
const rscServerBuildOutput = await viteBuild({
envFile: false,
ssr: {
// Externalize every file apart from node built-ins. We want vite/rollup
// to inline dependencies in the server bundle. This gets round runtime
// Inline every file apart from node built-ins. We want vite/rollup to
// inline dependencies in the server bundle. This gets round runtime
// importing of "server-only". We have to do all imports because we can't
// rely on "server-only" being the name of the package. This is also
// actually more efficient because less files. Although, at build time
// it's likely way less efficient because we have to do so many files.
// Files included in `noExternal` are files we want Vite to analyze
noExternal: /^(?!node:)/,
// As of vite 5.2 `true` here means "all except node built-ins"
noExternal: true,
// Can't inline prisma client (db calls fail at runtime) or react-dom
// (css preinit failure)
// (css pre-init failure)
external: ['@prisma/client', 'react-dom'],
resolve: {
// These conditions are used in the plugin pipeline, and only affect non-externalized
// dependencies during the SSR build. Which because of `noExternal: /^(?!node:)/` means
// all dependencies apart from node built-ins.
// dependencies during the SSR build. Which because of `noExternal: true` means all
// dependencies apart from node built-ins.
conditions: ['react-server'],
},
},
Expand Down

0 comments on commit 47ef5d0

Please sign in to comment.