-
Notifications
You must be signed in to change notification settings - Fork 425
feat: support server-only and client-only modules (#2162)
#2167
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
base: main
Are you sure you want to change the base?
Changes from all commits
f93fc92
54fc19b
79e4e9d
a1fe0d9
e2ccf48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@solidjs/start": minor | ||
| --- | ||
|
|
||
| Add support for `server-only` and `client-only` modules |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,6 +209,29 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> { | |
| }), | ||
| lazy(), | ||
| envPlugin(options?.env), | ||
| { | ||
| name: "solid-start:boundary-modules", | ||
| enforce: "pre", | ||
| resolveId(id, importer, { ssr }) { | ||
| if (id === "server-only") { | ||
| if (!ssr) | ||
| this.error( | ||
| `Attempt to import 'server-only' in a client module: ${importer}`, | ||
| ); | ||
|
Comment on lines
+218
to
+220
|
||
| } else if (id === "client-only") { | ||
| if (ssr) | ||
| this.error( | ||
| `Attempt to import 'client-only' in a server module: ${importer}`, | ||
| ); | ||
|
Comment on lines
+223
to
+225
|
||
| } else { | ||
| return null; | ||
| } | ||
| return "\0solid-start:boundary-modules:id"; | ||
| }, | ||
| load(id) { | ||
| if (id === "\0solid-start:boundary-modules:id") return "export {}"; | ||
| }, | ||
|
Comment on lines
+229
to
+233
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the returned value is just the fixed "export {}", this will not cause any actual bugs. This can be regarded as a style suggestion.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Starting from Vite 6, Each environment has an isolated module graph. However, here it is specifically bound to the environment, so server-only and client-only actually point to different modules. |
||
| }, | ||
| { | ||
| name: "solid-start:virtual-modules", | ||
| async resolveId(id) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.