This is a starter for Vite in a monorepo setup.
This starter uses pnpm as a package manager. The packages are internal packages.
apps/dashboard
: a Vite apppackages/maths
: a math librarypackages/ui
: a stub React component library
This starter also demonstrates how to get tree-shaking working in Vite dev servers for internal packages.
- Vite dev server doesn't play nice with Barrel files.
- It's common to see packages have an entry file (
index.ts
) and all the source code under asrc
folder. - Internal packages are designed to not have a build step. The apps importing the packages want to reference the source for fast HMR.
Using exports
in package.json to export the src
folder:
"exports": {
"./*": "./src/*/*.tsx"
}
See packages/ui
for example usage.
Reference: Node.js API: Package entry points
Add a path alias to the app's tsconfig.json
:
"paths": {
"maths/*": ["../../packages/maths/src/*"]
}
Configure path alias in vite.config.ts
:
resolve: {
alias: {
maths: path.resolve(__dirname, '../../packages/maths/src');
}
}
See packages/maths
for example usage.