I'm developing a Svelte module for publishing as an npm package. I'd like to include examples that are longer than a few lines. What's the standard approach for this?
I don't think it makes sense to burden the original module with additional dependencies needed for examples. I could create a separate Github project mymodule-examples, but it also feels wrong to separate the module and examples into two repositories. Due to the nature of sveltekit, each example requires several files.
update: Quote from docs that makes me feel this is the suggested way to organize/publish libraries made with SvelteKit:
A component library has the exact same structure as a SvelteKit app, except that src/lib is the public-facing bit, and your root package.json is used to publish the package. src/routes might be a documentation or demo site that accompanies the library, or it might just be a sandbox you use during development.
I believe it is possible to control what is uploaded to NPM:
[The
filesfield] tells npm which files it will pack up and upload to npm. It should contain your output folder (dist by default)...To exclude unnecessary files (such as unit tests, or modules that are only imported from src/routes etc) you can add them to an .npmignore file. This will result in smaller packages that are faster to install.
So, you can manually control what is uploaded to NPM via:
package.json files field (whitelist).npmignore (blacklist)As for dependencies, I believe you can control these with dependencies and devDependencies:
dependencies: modules needed by your library.devDependencies: modules needed by examples, but not by your library.Further reading:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With