Skip to content
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

RSC: Fix noExternal rule for server build #8961

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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