DEV Community

Discussion on: Build a typescript component library with Vite

Collapse
 
andrioid profile image
Andri

Do you know how we can use the vite build --watch and somehow get the type declaration files copied? I can use "concurrently", but that seems heavy handed.

Collapse
 
ghiscoding profile image
Ghislain B. • Edited

I'm also having this problem after following this great article, I guess that the other option would be to run vite build --watch without the type declaration, which is a lot faster, and completely disregard the import error in your application. I added myself a separate script ("build:types": "vue-tsc --emitDeclarationOnly") for creating the type after the build watch started, so this way it removes the import warning and I can still develop, but like I said earlier even with the warnings you can still develop and once you're done with the component then run a full build components and you will get all types back. Another option could be to use vite-plugin-dts but I had issues with it, it is however much faster than vue-tsc

Also note that you probably don't need the mv command (which is not cross platform, at least it doesn't work on Windows), you can simply add this tsconfig "declarationDir": "dist"

Collapse
 
josip2312 profile image
Josip Ivancic

I would suggest just developing the components regularly without a watcher, once you are finished you can check the actual build output, but it shouldn't ever be different than the local one.