Discussion: make Vite more friendly to library development (like storybook)
See original GitHub issueDo NOT ignore this template or your issue will have a very high chance to be closed without comment.
Describe the bug
I am developing a component library, using vite as a local dev environment (like storybook). I also build the demos with vite and deploy it, so that our designers can see my demos.
In my case, the component library consists of many component, and each component is a separate package. So it is a monorepo, like this :
packages
βββ button
β βββ demos
β β βββ _theme.tsx
β β βββ demo1$.tsx
β β βββ demo2$.tsx
β β βββ index$.md
β βββ src
β β βββ Card
β β β βββ demos
β β β β βββ demo1.tsx
β β β β βββ demo2.tsx
β β β βββ index.tsx
β β β βββ style.module.css
β β βββ index.tsx
β β βββ style.module.css
β βββ declare.d.ts
β βββ index.html
β βββ package.json
β βββ tsconfig.json
β βββ vite.config.ts
βββ card
βββ demos
β βββ _theme.tsx
β βββ demo1$.tsx
β βββ demo2$.tsx
β βββ index$.md
βββ src
β βββ index.tsx
β βββ style.module.css
βββ declare.d.ts
βββ index.html
βββ package.json
βββ tsconfig.json
βββ vite.config.ts
I make it works (see the reproduction repo, but there is some flaws and hacks in it. It is because that vite keeps assuming the whole project is a vite app. (In my case, it is actually a package for my component).
Here is some flaws that make vite not an ideal for library development. You can observe them in the reproduction repo.
- I want to move the index.html into
/demos
, because it is config for demos, not the component package. I am not able to do that because I have set vite root to/
(because demos import things from/src
), and vite hard-code html path as${root}/index.html
. (You can try to move it in the reproduction repo) - Vite reads
#{root}/package.json
and βtreat it like a config for viteβ. But in the case of library development, it is made for the npm package!- I am forced to put
@pika/react
and@pika/react-dom
inside package.json#dependencies. All users of my package will install them! I have created an issue at vite-plugin-react. - The βpackage.json#sideEffectsβ has effects on vite build, which is unexpected. After investagte, it is because the rollup-plugin-node-resolve used by vite accidentally reads it.
- As the comment points out,
"type": "module"
inside package.json also has surprising effects on vite.
- I am forced to put
- I have to manually list many devDependencies inside vite.config.ts#optimizeDeps#include. Because:
- Dependencies of my library demos should be devDependencies of the package. But vite only optimizes
package.json#dependencies
by default.
- Dependencies of my library demos should be devDependencies of the package. But vite only optimizes
I love vite. I think it can be a very handy tool for library development. (Better than storybook!)
Reproduction
https://github.com/csr632/test-vite/tree/lib-monorepo
Based on the reproduction repo, how can the workflow and file structure be improved?
System Info
- required
vite
version: 1.0.0-rc.4 - required Operating System: MacOS
- required Node version: 12.x
Issue Analytics
- State:
- Created 3 years ago
- Reactions:31
- Comments:10 (6 by maintainers)
Top GitHub Comments
I have added your statement into the issue body.
This issue has been locked since it has been closed for more than 14 days.
If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Vite version. If you have any other comments you should join the chat at Vite Land or create a new discussion.