feat(devex): vite#35247
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR introduces Vite as an alternative build tool to webpack to improve development speed. The changes include:
-
New Vite configuration and plugins:
- Added
vite.config.tswith React support and CORS configuration - Custom plugins for HTML generation and Kea typegen support
- Proper asset handling for Lottie animations and JSON files
- Added
-
Infrastructure changes:
- New scripts:
bin/start-frontend-viteandmprocs-vite.yaml - Modified
bin/startto support--viteflag - Updated package.json with Vite dependencies
- New scripts:
-
Frontend adaptations:
- TypeScript module declarations for Vite's URL imports
- Template modifications in head.html for Vite development server
- Barrel file pattern adoption in some components
The changes maintain backward compatibility by keeping the existing webpack setup while providing an opt-in path for using Vite.
Confidence score: 9/5 (3/5)
- This PR is moderately safe to merge as it adds functionality without removing existing build system
- Score reflects concerns about error handling in HTML plugin and potential environment-specific issues
- Files needing attention:
- frontend/vite-html-plugin.ts: Error handling needs improvement
- frontend/src/lib/animations/animations.ts: Type 'any' usage should be reviewed
- posthog/templates/head.html: Hardcoded development server port
11 files reviewed, 11 comments
Edit PR Review Bot Settings | Greptile
|
|
||
| {% if debug %} | ||
| <script type="module"> | ||
| import RefreshRuntime from 'http://localhost:8234/@react-refresh' |
There was a problem hiding this comment.
style: Consider using a configuration variable for the Vite dev server port (8234) instead of hardcoding it in multiple places
|
Size Change: -60 B (0%) Total Size: 2.62 MB ℹ️ View Unchanged
|
mariusandra
left a comment
There was a problem hiding this comment.
gonna try it, but for now one comment inline
There was a problem hiding this comment.
Instead of all of this, one other option is to just add frontend-vite to the default mprocs, with autostart: false. Then whoever wants can opt in by turning the default off
There was a problem hiding this comment.
I suppose that's a good idea so that we don't have to keep two very similar mprocs in sync, but ideally this is merged, tested as experimental (not really ready for all devs), and once we can ship features on top of it, we remove the flag + other mprocs.
15a9ffe to
34c23c3
Compare
📸 UI snapshots have been updated18 snapshot changes in total. 0 added, 18 modified, 0 deleted:
Triggered by this commit. |
There was a problem hiding this comment.
vite complained about it being a .js file
| key: SDKKey.NEXT_JS, | ||
| tags: [SDKTag.WEB, SDKTag.RECOMMENDED], | ||
| recommended: true, | ||
| image: require('./logos/nextjs.svg'), |
There was a problem hiding this comment.
can't use require in vite without some bloated commonjs plugin
| export function htmlGenerationPlugin(): Plugin { | ||
| return { | ||
| name: 'html-generation', | ||
| buildStart() { |
There was a problem hiding this comment.
can remove this buildStart as we don't ever build in this scenario
| configureServer(server) { | ||
| server.httpServer?.once('listening', () => { | ||
| setTimeout(() => {}, 100) | ||
| }) |
There was a problem hiding this comment.
todo: output a log to the terminal about visiting 'localhost:8010', currently only shows "visit localhost:8xxx" which is the vite dev server, not what you should visit.
There was a problem hiding this comment.
Woohooo 🙌 This is much faster for me and was a great experience when i gave it a trial run, thank you for working on it!
Will leave the stamp for @mariusandra since he's most familiar with the current build process - once merged I'll use it locally when developing and let you know if I encounter any snags.
mariusandra
left a comment
There was a problem hiding this comment.
I had a look and found one more require() that was throwing a lot of errors. Pinging Tom to see if the workaround is worth it. Other than that, I'm also not sure how or why the esbuild utils.mjs is used. I remember that my index.html got a lot of crap in it... but where did it come from, if we should totally be using vite now?
Still some typescript errors to fix. I'm not sure what's causing them - had a 10min attempt, and managed to fix something by changing a type from JSX.Element to React.ReactNode, but it felt a bit like magic... so not sure 🤔
📸 UI snapshots have been updated2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
Triggered by this commit. |
📸 UI snapshots have been updated2 snapshot changes in total. 0 added, 2 modified, 0 deleted:
Triggered by this commit. |
980788b to
725fc1b
Compare
Co-authored-by: Marius Andra <marius.andra@gmail.com>
📸 UI snapshots have been updated20 snapshot changes in total. 0 added, 20 modified, 0 deleted:
Triggered by this commit. |
|

Problem
Known limitations
Run
pnpm install && bin/start --viteHow it works
--vitetellsbin/startto launchmprocs --config bin/mprocs-vite.yamlPOSTHOG_USE_VITE: '1'/bin/start-frontend-vitebin/turbo --filter=@posthog/frontend start-vitewhich...vite.config.ts:src/=>dist/(without ESBUILD scripts/tags in the HTML)public=>frontend/src/assets/(so vite doesn't complain)Not tested
Changes
require()inside the frontend (storybook stories are fine as this still uses webpack)How did i test this?
Vite (local)
rm -rf **/node_modulespnpm installbin/start --vitehttp://localhost:8010/as normal ⚡Normal ESBUILD (start/local)
bin/starthttp://localhost:8010/as normalNormal ESBUILD (build/local)
cd frontend && pnpm build