-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
svelte-kit package #1499
svelte-kit package #1499
Conversation
Re TypeScript declarations: |
Oh, that's good to know. svelte2dts looks particularly promising, especially if it can be coaxed into generating declaration files for Svelte components with JSDoc types. May take a stab at integrating that later if I get time, though I suppose an alternative could be to just support vanilla JS for now and worry about types in a follow-up |
We'll have to add some docs for this as well |
I had a crack at integrating @dummdidumm @halfnelson I did notice that |
I don't see a near future where this is happening, precisely because of inferred types. I also think that it's better to just let TypeScript handle this stuff, especially since the wrapper to get this working is that small (the svelte2dts code is only a couple of hundred lines). |
For generating Svelte type definitions there's also https://github.com/IBM/sveld (no |
Two things that come to my mind:
|
any non
yes, any // svelte.config.js
export default {
kit: {
package: {
exports: ['index.js']
}
}
}; ...and defining the API in import { X, Y, Z } from 'your-lib'; |
* first stab at svelte-kit package command * include/exclude files as well * make typescript happy * tidy up * improve error message * exclude underscore-prefixed files from exports by default * move files * add docs * changeset * gitignore package directory * update lockfile, who knows why * update unit tests * copy over readme
Just a warning, pls try to not use sveld as it cannot parse custom css such as sass and cannot detect props which are exported as |
@@ -1,5 +1,4 @@ | |||
.DS_Store | |||
node_modules | |||
/.svelte-kit | |||
/build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Rich-Harris did you mean to remove both /build
and /functions
here?
Any chance we can get a new kit release for this? #1543 |
* 'master' of https://github.com/sveltejs/kit: Version Packages (next) (sveltejs#1543) type fixes for adapter-node and adapter-static (sveltejs#1578) Upgrade to Vite 2.3.3 (sveltejs#1580) fix: improve getRawBody parsing & handle error(s) (sveltejs#1528) create-svelte: add svelte-check for TS (sveltejs#1556) pass validated svelte config to adapters (sveltejs#1559) types: group related and reduce potential inconsistencies (sveltejs#1539) Use sveltekit tag on StackOverflow (sveltejs#1558) Fix create-svelte build-template script (sveltejs#1555) Remove err param from Polka .listen() callback (sveltejs#1550) bump: polka and sirv versions (sveltejs#1548) svelte-kit package (sveltejs#1499)
How is this supposed to work for single-component packages? If I add an index file that simply reexports the Svelte component, // src/lib/index.js
export { default } from './MyComponent.svelte' and then install the package and try import MyComponent from 'my-package' I get
The easiest solution to this in the past was to use the |
I'm not super familiar with |
I don't think using a import MyComponent from 'my-package' Would't I have to do this? import MyComponent from 'my-package/Index.svelte' If so, I'd say it's better to keep import MyComponent from 'my-package/MyComponent.svelte' |
Is there any workaround to do it until it's possible with |
Finally I did it with rollup, in addition to vite in my svelte-kit project. |
This is an early and incomplete attempt at
svelte-kit package
(#518). It adds a command that packages up the contents of thesrc/lib
folder for publishing to npm, and some corresponding config:Specifically, it:
src/lib
that are specified byconfig.kit.package.files
"exports"
map that includes all the files specified byconfig.kit.package.exports
It doesn't apply other transforms, either Vite built-in transforms or those specified by user plugins. I'm open to persuasion on that front but I think it's better to keep everything as simple as possible.
I'd like it to emit
.d.ts
files for.ts
files and, if possible (if it even makes sense).svelte
files that contain TypeScript. Not familiar enough with the TypeScript API to know how to go about that.The expected publishing workflow looks something like this:
Other possibilities mentioned in #518:
_
prefix fromexports
automaticallysrc/lib/Foo/index.svelte
->import Foo from 'my-lib/Foo'
Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
Changesets
pnpx changeset
and following the prompts