Open coryhouse opened 2 years ago
Vite benefits over create-react-app
- Faster startup. (Uses esbuild with rollup instead of webpack. Uses separate TypeScript project for Vite config to speed builds too.
- Scales better. Dynamically passes native ESM to the browser for speed. Code is "lazy" processed the moment it's needed to display the screen. (create-react-app compiles the output on each save first). (See type="module" in index.html).
- Prebundles dependencies via esbuild (written in Go so it's fast)
- Consistently faster HMR (even for huge projects) since it's handled over ESM
- Supports glob imports
- Automatically preloads chunks
- Easily generate a reusable component library via library mode
- Supports SSR via a plugin or libraries
- The CLI prompts for choices.
- Works for other frameworks like Vue, Svelte, etc too.
Notable differences from create-react-app
- Create via
npm init vite
main.tsx
is the entry point instead ofindex.tsx
- index.html is in root instead of /public
- No testing built in, but Vitest is easy to add
- Targets modern browsers by default
- Env vars are under
import.meta.env
insteadMore goodies in awesome-vite
Other tips
Vite benefits over create-react-app
Notable differences from create-react-app
npm init vite
main.tsx
is the entry point instead ofindex.tsx
import.meta.env
insteadMore goodies in awesome-vite
Other tips
Speed up e2e tests calling Vite