-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Lib mode doesn't export types #2989
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
Comments
Have you checked
This doesn't work together with |
You can use {
"build:types": "tsc -m amd -t ESNext -d --isolatedModules false --moduleResolution node --esModuleInterop --jsx react --outFile dist/index.js src/main.ts && rm -rf dist/index.js ",
} |
@keelii, but shouldn't vite provide this solution by default since it natively supports typescript? |
When vite do this for you, it's not cheap, and if you do it by using Because even if you use tsc, it's not so fluently. you will need concat to a single d.ts file which is not directly supported will in typescript, you need some tricks to let it work. |
Mh seems that it was already requested some time ago #2049 IMO it may make sense to generate declaration files in library mode, cause a published library should serve declarations. That just make the ecosystem a better place. |
@Shinigami92, any dates or updates on when this would go to vitejs? That's the only thing that is preventing me from using on my company. |
@darklight9811 I don't know if there is currently an open PR, if not please feel free to jump in and create one 🙂 |
But even without this in core, this shouldn't prevent you to use it as you can generate the types on the side as was shown in the comments in this issue. |
@patak-js, I don't know if I'm doing something wrong, but that command is not working and tweaking it also didn't work for me. |
@darklight9811 also tried this? #2989 (comment) |
Just tried to use Vite for a serious project at my company and this is preventing me from using it as well. Generating type definitions is something that should be supported by default, especially when the Typescript support in Vite is as good as it is already. Really disappointed that this hasn't been considered as a standard feature so that devs don't have to deal with low-quality workarounds. |
@samwightt As I already wrote here: #2989 (comment) I'm sorry for you that you may have a misunderstanding about how open source works 🙁 |
You can use https://github.com/egoist/tsup. Example usage,
The |
I understand the reasoning behind not doing this but I think it should be reconsidered. If Vite did this by default it would be a sort of pit of success that would benefit the broader JS/TS community. If it's not the default and people start using Vite to build libraries I imagine we will have lots of them published without types. That in turn will lead to a lot of churn and lots of github issues being created (in the respective libraries). |
This comment has been minimized.
This comment has been minimized.
What does sass have to do with TypeScript declarations?! Could you explain a bit? |
@Shinigami92 , sass files are generating css modules that can be exported and are dynamically typed..... |
This. Currently I'm actively discouraging people in my network from using Vite for libraries. Not having this on by default, especially when everything else in library mode just works, will objectively make the JS ecosystem worse. Usage of Typescript is only growing, so it would be good for Vite to be a good citizen and support this by default. I'm not angry or annoyed that this is not the default, and I'm not expecting any work to be done to get this feature working. I just want to make sure that maintainers understand how big of a deal this feature is, and that not having it is a really glaring oversight when the rest of library mode is as polished as it is. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@Sanjade Do you like to create a feature request issue for this? Then we have a fresh new issue and we can better track it 🙂 |
Moved to #3461 |
Describe the bug
I'm using vitejs to build a react typescript library, I started building it with a plain rollup, but decided to migrate, so I have put everything accordingly. Fixed some bugs, added some packages, but when I export it, it doesn't export the typings (.d.ts) along with the es and umd files, even if I set declarations to true inside of the tsconfig. But it does export successfully both files.
I tried tweaking rollup but to no avail, and also couldn't find anything related to this in the issues or google at all.
Reproduction
Install vite with the "react-ts" template, follow the documentation steps to use lib mode, make a simple component and export it from the output file, and build it.
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: yarn
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: