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

Add experimental SSR support for the dev server #1086

Merged
merged 3 commits into from
Sep 26, 2020
Merged

Conversation

FredKSchott
Copy link
Owner

@FredKSchott FredKSchott commented Sep 18, 2020

Based off of work done in an internal project with @lukeed and in https://github.com/Rich-Harris/snowpack-svelte-ssr with @Rich-Harris

Changes

  • Add an experimental API for the dev server (exposed as import {unstable__startServer} from 'snowpack')
  • Add SSR support for the dev server via this new API.
  • Add SSR support for plugins, and adds support to the svelte plugin specifically.

Testing

  • Note: experimental/unstable means we do not yet document this in our docs, or commit to semver until it is no longer considered unstable
  • Not exposed to the user, but tested manually in the projects mentioned above.

@FredKSchott FredKSchott requested a review from a team as a code owner September 18, 2020 04:57
@vercel
Copy link

vercel bot commented Sep 18, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/csvqn0n6v
✅ Preview: https://snowpack-git-experimental-ssr.pikapkg.vercel.app

@FredKSchott
Copy link
Owner Author

@Rich-Harris This file is honestly the best take on importing ESM from the dev server directly into Node.js that I've seen or can think of, at least until those ESM loader hooks are finalized: https://github.com/Rich-Harris/snowpack-svelte-ssr/blob/master/tasks/SnowpackLoader.js

It would be out of scope of all users of SSR to implement this themselves. How do you feel about us pulling this into Snowpack directly or shipping this as a separate utility helper package to help people integrate SSR with Snowpack?

@FredKSchott FredKSchott changed the title add SSR support for the dev server Add experimental SSR support for the dev server Sep 18, 2020
@Rich-Harris
Copy link
Contributor

I was secretly hoping you'd suggest something like that! The main reason I didn't bring it up yet was that the result of this approach isn't totally spec compliant (cycles, live bindings) and figured you might prefer something more robust if it's to be part of Snowpack. (Also, I realised that it caches too aggressively - modules aren't invalidated when their dependencies change. Need to fix that.)

But more broadly, yeah, I think it would be super useful to have this functionality as part of the API

@@ -6,6 +6,7 @@ import {getExt, readFile, replaceExt} from '../util';

export interface BuildFileOptions {
isDev: boolean;
isSSR: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants