Skip to content

Commit

Permalink
RSC: Fix noExternal rule for server build (#8961)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Jul 25, 2023
1 parent 9a552c6 commit 9ac5ab2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
13 changes: 7 additions & 6 deletions packages/vite/src/rscBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ export async function rscBuild(viteConfigPath: string) {
root: rwPaths.base,
plugins: [
react(),
{
name: 'rsc-test-plugin',
transform(_code, id) {
console.log('rsc-test-plugin id', id)
},
},
// {
// name: 'rsc-test-plugin',
// transform(_code, id) {
// console.log('rsc-test-plugin id', id)
// },
// },
rscAnalyzePlugin(
(id) => clientEntryFileSet.add(id),
(id) => serverEntryFileSet.add(id)
),
],
ssr: {
// We can ignore everything that starts with `node:` because it's not going to be RSCs
noExternal: /^(?!node:)/,
// TODO (RSC): Figure out what the `external` list should be. Right
// now it's just copied from waku
Expand Down
13 changes: 9 additions & 4 deletions packages/vite/src/waku-lib/build-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ export async function serverBuild(
// ...configFileConfig,
root: rwPaths.web.base,
ssr: {
noExternal: true,
// TODO (RSC): The code below is pretty much what waku does, but I don't
// understand it
// Externalize everything except files that have 'use client' in them
// (this includes packages in node_modules that you use that have
// 'use client' in them)
// Files included in `noExternal` are files we want Vite to analyze
noExternal: Object.values(clientEntryFiles),
// TODO (RSC) This is the original code from waku. I think we can simplify it as above
// The code below will for most basic cases just be `[ '..' ]`, which we
// believe to be overly broad
// noExternal: Object.values(clientEntryFiles).map((fname) => {
// return path
// .relative(path.join(rwPaths.web.base, 'node_modules'), fname)
// .relative(path.join(rwPaths.base, 'node_modules'), fname)
// .split('/')[0]
// }),
},
Expand Down
6 changes: 0 additions & 6 deletions packages/vite/src/waku-lib/rsc-handler-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ const vitePromise = createServer({
resolve: {
conditions: ['react-server'],
},
ssr: {
noExternal: /^(?!node:)/,
// TODO (RSC): Figure out what the `external` list should be. Right
// now it's just copied from waku
external: ['react', 'minimatch', 'react-server-dom-webpack'],
},
appType: 'custom',
})

Expand Down

0 comments on commit 9ac5ab2

Please sign in to comment.