Vite 3.0
vitejs.dev
vitejs.dev
Has Webpack really been dethroned as the go-to bundler?
[0] https://laravel-news.com/vite-is-the-default-frontend-asset-...
At this point yes. I'm sure there are still some things that you will need Webpack for, but in my experience I have yet to find one of those instances. Vite is not just way way way faster than Webpack, it's also way simpler.
Configuring a React project from scratch with Webpack is an undertaking, especially if you're not seasoned with Webpack configurations. Vite on the other hand is super simple to setup, I typically don't even reach for the starters that vite offers because it's just as easy to do an `npm init -y` and then install it manually.
I work for a web dev agency and we have migrated all of our existing projects to Vite, and advised any new projects to not use Webpack unless there is a very specific reason and other solutions have been exhausted.
Vite has been great in the vanilla and Vue projects I've used it for. I didn't think the speed bump would be as noticeable as it was. I'm really happy to hear it is getting more usage in frameworks like Laravel.
Why do people do this? I've always used the official way (CRA), and never had any issues with it. If you need to adjust webpack configuration, there are third-party packages that work very well in practice (like craco). Yet reinventing the wheel over and over again seems to be popular.
> Vite is not just way way way faster than Webpack, it's also way simpler.
It's not reinventing the wheel. It's just significantly improving the wheel.
I think building js in js is just not fast enough anymore, everyone is moving towards compiled languages for building their apps. The next winner in the space will be something like vite that uses a compiled language under the hood (vite uses esbuild, which is written in Go).
The move to 3->4 was painful as 25% of my projects started to move to 4 and no longer worked with 3. So I was stuck with some legacy packages during a time I was upgrading from Vue 2 -> 3. AFAIK they Rails didn't even get to Webpack 5 in practice by the time I left.
Vite came to the rescue at a perfect time.
I've been experimenting with some stuff using esbuild directly in a "targeted" way that builds only a few things with most stuff just Typescript transpilation only (again). I've almost got a feeling the next winner may just be Typescript+esbuild, but not at all because esbuild is fast or written in Go. It may still be Typescript+rollup, given the hints of what's coming in the next Rollup major. (Typescript is still in JS and getting faster every release, with incremental build support for large projects getting better all the time. Rollup is still in JS and still a decent esbuild competitor.) In a "no build"/"targeted build" world it's not really speed that matters but a minimal, targeted API that's easy to automate as you choose targets to build and it may be the case that the time of the "kitchen sink plus a million plugins" builder is over.
Otherwise I've been using Parcel without much issues with quite less configuration.
https://vitejs.dev/guide/why.html#why-not-bundle-with-esbuil...
> While esbuild is blazing fast and is already a very capable bundler for libraries, some of the important features needed for bundling applications are still work in progress - in particular code-splitting and CSS handling. For the time being, Rollup is more mature and flexible in these regards. That said, we won't rule out the possibility of using esbuild for production build when it stabilizes these features in the future.
Overall, ESBuild feels like a much lower-level tool than Vite. It's great for smaller projects or projects that require absolute and complete control over their builds, but it takes more time to setup in most cases and often requires writing your own build scripts.
I suppose it wouldn't scale if the app got too big and complicated.
[1] https://github.com/skybrian/serialviz/blob/main/package.json
If I don't write my own build scripts how else am I going to show my coworkers how big brained I am? I need to assert my intellectual superiority somehow...
I think of Vite as a bundle of esbuild and other tools glued together nicely into one thing which can manage your entire project.
If you just want esbuild + hot reloading then dev-server-esbuild might be a good option: https://modern-web.dev/docs/dev-server/plugins/esbuild/ But really vite isn't much more complex or opinionated compared to it.
"scripts": {
"build": "esbuild src/app.ts src/app.css --bundle --sourcemap --outdir=site",
"dev": "npm run build -- --servedir=site",
}
Unless you mean something different by "hot reloading" than "recompile on page reload?"It's really a magical experience to have your code open in one window, your browser open next to it, and as soon as you hit ctrl-s instantly see the page change. I won't tweak CSS any other way, changing sizes, colors, etc is amazing with hot reload.
What exactly is the "next generation" part here? The composition? That's also not new, so I think I'm either missing something very obvious, or they need to do a better job explaining how Vite is actually different.
That sounds like "incremental improvement", not "next generation tooling". But maybe my expectations are too high.
While all previous ones, bundled for both dev and prod. This is what makes vite a different generation. And results in massive performance boost for dev "build" And HMR
For dev, vite _doesn't_ bundle, it sends your site basically unmodified (as individual files) to the browser since most browsers are already capable of running anything you're using anyway... so if you change one file, that one file is patched, not the whole bundle that depended on it..
since there's no bundling, the initial start time is nearly instant...
webpack hot reload is NOTHING like this hot reload
"Native" support for modules and TypeScript, so during development there is no bundle process needed, which is usually the most time-consuming process.
Isn’t this exhausting?
Is it impossible to design good contracts without having to break compatibility every year?
In most other language ecosystems it would convey incompetence.
I get it, Linux does its own thing with versions, and so do browsers, so it's hip to just increment major whenever you feel like it apparently.
EDIT: LOL at people downvoting GP because they dared to wonder if the frontend world needs another bundler shipping a non-compatible major version at least once a year. Stockholm Syndrome I guess, who doesn't want to update their configuration and see their plugins break every year?
Even Go, one of the most boring (in the good sense) languages, considered to do the same thing at some point (when included generics).
This is why when you npm add a dependency it defaults to the "^1.2.3" syntax, which means the dependency is upgradeable to the next minor version, which, as SemVer states, should be guaranteed to be backwards compatible.
Of course you can just disregard that, make breaking changes whenever you want and annoy your users enormously.
https://docs.npmjs.com/cli/v8/configuring-npm/package-json#v...
https://docs.npmjs.com/about-semantic-versioning
AFAIK Go doesn't follow any kind of versioning scheme (since they don't use a versioned module manager), but the project itself is semver-compliant. No breaking changes are introduced since Go 1.0 was released. The proposals for breaking language changes will be planned for Go 2.0. Generics aren't breaking old code.
There is no reason, unless your name is Linus Torvalds or you're marketing driven such as your browser, not to follow Semver. It's a good and simple idea.
I have no knowledge of which convention Vite uses.
https://semver.org/ https://docs.npmjs.com/about-semantic-versioning
That’s the sole reason for the squiggly marks and carets that exist in every package.json.
For eg: Consider CRA dependency upgrade from webpack v4 to v5. That change broke a lot of apps due to node not being polyfilled.
If CRA did the change in minor version, then it would have result in breaking changes for many apps and would completely undermine semantic versioning
(With that said, I'd love to see Next use Vite, but iirc the webpack dev works for Vercel [Nextjs parent] now)
[0]: https://swc.rs/
When there is ssr, there is runtime, more than just a dev/build tool.
That does not seem to be the truth. They offer a very different product than Next.
React falters because there are not many community contributing towards react integration.
Note: Vite team has done their job for react, but react itself has many concerns particularly due to commonjs that a dedicated person (or team) is needed for react
This is like saying NPM is language agnostic. Sure, technically it is. But we all know what it was built for and what the community is geared toward.
Angular is the same way, it has its own compiler and relies on custom build-time code to work. That's also why it isn't picked up by a lot of newer build tools that generally just work with normal JS.
[0]: https://parceljs.org/docs/
[1]: https://swc.rs/
Common things that break: specific operators (?.), caching issues, missing modules in the output bundle, build errors, etc.
Vite on the other hand hasn't had any such suprises so far.
However, the promise of zero config is made possible in part by "magic" (strange conventions), and by having configuration spread across multiple files (package.json, . parcelrc, custom plugins which for some grave reason you can't use until you publish them to npm)
I really wish Parcel had sane configuration — I want to like it so much, but alas, it falls pray to the pendulum effect.
As your app starts to grow, you'd definitely not want 1000s of modules loading in your browser.
Seems like something that gets you from 0-60 quickly, and becomes a pain after. Similarly, the different choice of bundlers in development and production would well lead to difference in behaviour / hard to catch bugs.
Edit: lol I should have read your post more closely. Yes, the different strategies can cause bugs; there's much more shared between the two pipelines than there used to be so this situation is improving. We actually had really bad compatibility with problems six months ago and it was still easily worth the trouble for the performance improvement.
The individual modules are only served during development, but even then startup/load is faster than our previous webpack setup by an order of magnitude. When you build for production, you still end up with a bundle like you had previously.
Plenty of serious support behind it.
Not sure how you'd end up with "1000s of modules in your browser", unless you have some mega-project with an unwieldy package.json. I have a pretty complex Vue project app and it loads <100 .js files async and the vast majority are 100b and 95% will cache on the first load and never change. It's really not that big of a deal for modern browsers to load lots of tiny js files from your local machine in development.
I've found it to be way faster than Webpack for dev build times which is all that really matters to me.
This being the case, I am not sure I'd really have a reason to migrate over to Vite on this project.
I've been considering switching to Vite because it should make the SSR + hydration config much simpler and I would get HMR (hot module reloading) which will probably speed my iteration times if it works as expected.
the only reason i switched to Vite was that in my experience with Webpack build times were not quick and i got annoying JS bundling issues like syntax errors (!). That’s really the main difference I saw between the 2. But it was a while ago and maybe webpack has gotten better again, in which case they’re both very similar.
I know, it still seems crazy what's happening at the frontend ... but Vite brings substantial advantages compared to the old standard. Same thing with the next-gen frameworks like Svelte, SolidJS or Vue 3 (composition API) that are substantially better than the old ones (mainly regarding DX). Another welcoming example are the quite new E2E testing frameworks like Cypress or Playwright.
edit: fixed after reading docs.
https://vitejs.dev/guide/features.html#css
npm add -D sass
Wait what, again? I thought we all silently agreed to use the mature/legacy frameworks React and Angular until the proper WASM arrives so that we could burn all of JS/CSS/HTML...
We did. But people without real problems to solve will continue reinventing the wheel, while we silently churn away on actual products with stable tooling.
Microframeworks are slightly better, especially if they support no-build setups since then a "build step" for prod is only bundling and minification.
So it sounds like Webpack was never really mature, or too late in getting ported to Go before Vite took over?
I've worked on projects with hundreds of thousands of LOC compiling with Webpack. Build time has literally never been a concern for me. The entire point of tooling like Webpack is that it's written in JS because dealing with interop between native binaries is an absolute nightmare. It's a feature, not a bug. The same reason we moved to JS based SASS/PostCSS compilers.
Some folks have attempted it, but not completed vite support.
This is nothing new in angular land. There are multiple third party libraries and framework which support react, vue, svelte and even solid, but not angular.
Hopefully, they will update soon
That's a very strange change
The Web's main problem is that to the extent that it has a UI toolkit, it's god-awful. We should have spent all this time since it became clear "web apps" aren't going away strengthening HTML, and especially the various form elements (better tables and some kind of list view like other platforms have would be great, too).
Instead it's largely stuck in place, and we hack in poor-performing custom half-broken elements that are different on every site, wasting absolutely incredible amounts of both developer and user time. Truly, the time-cost to humanity of web UI's inadequacy is huge.
Angular and Vue were the thing last I was paying attention. Now React is the thing. But not so fast, there's Next.js.
I think I've had enough, I will supplement my Django backend templates with handwritten CSS.
I think it has to do with frontend means designers/ux, and those people tend to like being in the spotlight and grab fame. Therefore it's logical that they just create / fork something instead of contributing to an existing project.
This results in buggy projects because they try to do everything, and unmaintained after a while. Usually they're also less thought out than with backend projects.
just don't upgrade random tooling all the time and you're good. most widely used JS stuff has an excellent backward compat story. (react itself is amazing in this regard IMO)
a corollary to this is that if you feel fatigued by having to constantly learn and upgrade your tooling, maybe you're just having regular old analysis paralysis and you're blaming the tooling for no good reason. just use the tools you already know and get going! you can build fantastic, modern-feeling software using only tools and knowledge from a decade ago.
Good luck with that in the NPM ecosystem
Note, it was different ~5 years ago. When we wanted to upgrade from react 15 to 16 for better runtime speed, we had to upgrade babel first and that required a webpack upgrade iirc. It was a mess. But the ecosystem has matured a lot since then and we haven't done major setup changes since. It just works.
Note that we're on React 17 now - 15 to 16 was hard but 17 was largely backward compatible. I expect 18 will be worth it too, the breakage is tiny. Like I said, React's backward compat story is real nice IMO :-) (and so is the tooling to help you address breaking changes)
Ha, this is actually a good idea that I didn't consider. I'll push for this, thanks!
There was a short lived explosion of frontend frameworks that grognards drag up like it's a relevant problem, but serving up HTML from a server side route has always been an option.
I went with Nextjs with all its bells and whistles and expressjs (99% of cases is enough). Now I'm currently moving to MLE projects at work.
I only pay attention to new tech only if here's a huge demand (ie. Plenty of Jobs and good $$$). Only then I start learning it.
Nextjs/React won the frontend battle (atm). It's almost impossible to keep up + being specialist. Heck, it's equally difficult to be a generalist with new things coming up every 3/6 months.
In many companies, you won't be tinkering with vite at all. The build person will do that, you will be reaping the benefits of it only.
Well, there are cobol devs for hire. So, tech alone is not sufficient to drive away all potential hires.
There might be other red flags
A few years ago there were tons of frameworks and they all worked a bit differently. New shit every week. IMO that's because no one had really figured out the right paradigm yet. Now we have (it's components) and the framework race has slowed way down (it's pretty much React, Vue, and Angular now). Even big changes in React like Hooks didn't break backwards compatibility. You can move pretty slow and steady on that front, if you want to.
Tooling is the next frontier. It's become obvious that compiling js in js itself is just not performant enough for large applications. We need a faster solution. There are a few contenders right now (esbuild, swc, bun; vite wraps esbuild) but I suspect within two years we'll have a pretty clear winner.
In general I think things move faster when we haven't found the right ideas yet, and that's why backend is more stable -- it's just older. There has been more time to iterate and figure out what works and what doesn't. Frontend will probably always be more chaotic than backend, but I think it'll be much less so as we start to agree on the web want it to look like.