Closed yukipastelcat closed 3 years ago
Does https://github.com/sveltejs/sapper/issues/774 help you in any way for now ?
Svelte components are commonly added to the devDependencies
instead.
With Sapper being discontinued in favour of SvelteKit it is unlikely this will get better documentation, but probably something that can be expanded upon more in upcoming documentation for SvelteKit.
@stephane-vanraes so it looks like I have to include .svelte
files to package distribution and specify "svelte" field in the package.json since rollup-plugin-svelte
and svelte-loader
are seem to be using this field.
Is your feature request related to a problem? Please describe.
I'm trying to build components library for Svelte with SSR support in this branch. However I stumbled upon several problems related to lack of documentation at these points.
Problem 1
It's unclear which package.json fields are used on import - I have to specify full path to cjs bundle in my import string:
Problem 2
It looks like the problem is that SSR components can't be used on client-side and vice-versa. I'm getting this error while trying to use my library in Sapper app:
It looks like while component is trying to mount on client it attempts to create new instance, which is impossible because Svelte compiler with
generate: 'ssr'
option outputs constant, which cannot be used with new:And if I try to import esm module, it doesn't contain methods needed for SSR.
Describe the solution you'd like Provide a documentation for building SSR components with an example/template.
Describe alternatives you've considered Alternative solution currently is to include
.svelte
files into package and importing them, in which case if you're planning to use library outside of Svelte/Sapper without bundler configuration for handling.svelte
files you'll end up with something like that:Additional context You can reproduce problems mentioned here by doing following:
Clone this branch, then run:
This will produce tarball, containing library package. Next up create Sapper app:
Then change contents of
src/routes/index.svelte
to following:and launch project.