I was really happy to discover Vite so I don't have to change the way my whole app works with Next.js. Here are the differences I found from Create React App:<p>* It does not have the overlay that warns you about eslint errors in your app; you can bring that back with the `vite-plugin-checker` plugin if you want.<p>* Running `vite` in IntelliJ with `npm run dev` will not show console logs in the IDE[1]. You don't need any of the solutions in that thread, though: just use a debug config.<p>* You can add TypeScript types to your env vars with vite-env.d.ts.<p>* Imports have to end in .tsx apparently:
`import Foo from './components/Foo.tsx';`<p>* No process.env:
Since your code is running in the browser rather than on a Node.js server, there is no process env var.<p>* Network tab shows a request for every file on initial load:
This is because each file is treated as an ESM module for hot reload. I couldn't figure out how to suppress these messages. It won't happen in production since they still use a bundler in prod to save network round trips.<p>1: <a href="https://ww.reddit.com/r/react/comments/zo6nay/how_can_i_view_console_messages_in_terminal_when/" rel="nofollow">https://ww.reddit.com/r/react/comments/zo6nay/how_can_i_view...</a>
We maintain a fairly large and complex CRA application, which has been migrated to Vite, but not fully.<p>Since a lot of changes would be needed and we are very risk averse (heavily regulated industry), we decided to do it piecemeal by first configuring Vite to behave exactly (or as close to as possible) like CRA and later removing these Vite configurations one by one (and making necessary code changes).<p>Currently our production builds are done through CRA while dev runs Vite. It works really well and minimal code changes were needed.<p>I've been wanting to release this config publicly to help others migrate to Vite, but have unfortunately not had time to.
When I switched from CRA/webpack to Vite I saw an order of magnitude speed-up, from minutes to a few seconds to compile. My laptop is old, needs replacing and starting to struggle but really shows how bloated webpack is.<p>It's fairly trivial to switch too, though means you need to start understanding how webpack/vite/package.json/tsconfig actually work. I did the same as the author and just made a new vite app and then copied stuff over and moved things as required.<p>The only complication I could really see where the environment variable names, which we only used two anyway.<p>By the way, I don't know why the author changed to using import 'components/blah' to '~/components/blah' as there's no real explanation in the blog post. The link for their commit is broken so can't see what the author has done.<p>You actually don't need to do that, all you have to do is set 'baseUrl' in your tsconfig (e.g. "baseUrl": "./src"). That tells typescript where to look for imports. Then Rollup via Vite handles the rest in compilation.
We recently migrated a Laravel app from Webpack (Laravel Mix) to Vite and it was mostly painless. Like OP, we had to update some imports that were using require and we also have a few different entrypoints which is not that well documented for the Laravel plugin.<p>Another issue we ran into was certain dependencies that only have .cjs versions that work fine when building, but during dev would fail to import via ESM correctly (the dependency itself is inside of a lazy loaded component). That means that if we're working on that part of the app, we need to do a full production build (6 seconds) between each code change and then use the prod build locally to test the feature. Annoying for sure but we can live with it until someone has time to update the dependency to one that natively supports being loaded via ESM.<p>If anyone is running the old Laravel build pipeline, I suggest upgrading now because it's potentially only going to get more and more complicated. If you have a simple frontend with some helper functions or a few Vue components, it should be pretty easy to reason about. The course on Vite from Laracasts was helpful to explain what some of the less documented features are, which was helpful for integrating with our application.
Good read! I have a huge CRA app I maintain at work, and we've been wanting to migrate to something else for years now. will have to check this out.
I’ve recently discovered rsbuild, which doesn’t have vite’s issue where a large application with many small modules takes minutes to load (in dev), because all 6000 files are an individual request.
CRA seemed near-abandoned when I first tried it in 2020. I'm surprised to hear that people are still recommending it as the default. Vite works so well out of the box.
It's easier than people think, and it's very well worth it. CRA is now obsolete and not getting any updates. Vite is so much faster as well (code changes reflect immediately).
Preact with Vite works very fast and Preact seems like a good long-term solution for projects which will use the single-page application approach (React seems to move ever-closer to the server rendering approach).