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

simplify svelte plugin #1221

Merged
merged 1 commit into from
Oct 5, 2020
Merged
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
9 changes: 1 addition & 8 deletions plugins/plugin-svelte/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,10 @@ module.exports = function plugin(snowpackConfig, pluginOptions = {}) {
})
).code;
}
// COMPILE
const ssrOptions = {};
if (isSSR) {
ssrOptions.generate = 'ssr';
ssrOptions.hydratable = true;
Copy link
Owner

Choose a reason for hiding this comment

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

Ah, I must have misunderstood this. Isn't the idea that hydratable is needed in SSR mode so that it generated hydratable markup, so that the client-side code can hydrate the SSR-generated markup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, hydratable just means that the client-side component is generated with the code necessary to hydrate the server-rendered markup. There aren't any constraints on the markup that it hydrates, it will repair the DOM as necessary

ssrOptions.css = true;
Copy link
Owner

Choose a reason for hiding this comment

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

The idea here was that CSS would be applied via JS directly in Svelte, so that you wouldn't need to handle our *.css.proxy.js proxy CSS files in SSR mode. Would love to hear your rationale behind removing this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The css option doesn't do anything in SSR mode. In DOM mode it causes the generated code to include the styles in the JS so that you don't need to figure out how to extract and serve a .css file — bit of a hack and not really recommended.

Any SSR solution will need to extract CSS, and either serve it as a file, consumed via a <link>, or embedding it in the rendered HTML:

const { html, css } = App.render(props);

return `<!doctype html>
<head>
  <style}${css.code}</style>
</head>
<body>
  ${html}
</body>`;

}

const {js, css} = svelte.compile(codeToCompile, {
...svelteOptions,
...ssrOptions,
generate: isSSR ? 'ssr' : 'dom',
outputFilename: filePath,
filename: filePath,
});
Expand Down