DEV Community

Nico Zerpa (he/him)
Nico Zerpa (he/him)

Posted on • Originally published at nicozerpa.com

2

Vite, the hassle-free alternative to Webpack

Webpack is the most popular module bundler to build complex JavaScript applications. It has more than 74 million downloads each month. However, Webpack is slow and configuring it is a monumental pain.

Thankfully, alternatives to Webpack have appeared, and one of them is Vite, from Evan You, the creator of the Vue.js front-end framework.

My favourite aspect of Vite is that it's fast with a capital F and supports JSX, Vue single-file components and TypeScript out of the box, with zero configuration. Just create your TypeScript/JSX file and Vite will parse it with zero hassle, in milliseconds.

Vite doesn't create itself the bundles. Under the hood, it uses two tools: Esbuild while you're developing, and Rollup.js to create the production bundle.

The recommended way to create a project using Vite is by running the command npm init vite in the command line.

You'll be asked to write the project name and which framework you want to use (if you want to use one). Once the project is created, you run npm install to install dependencies and then you can start creating and editing JS and HTML files.

Like Webpack, it has a built-in development server, that you can start with the command npx vite. When you need to create the production build, run npx vite build and everything will be built in the /dist/ folder.

The big drawback is that it doesn't have any tool for Server-Side Rendering (SSR) yet. They are working on it, but it's still experimental and not recommended for production.

Also, even though Vite can parse TypeScript, it doesn't do the type checking, it just converts it into JavaScript code. You should rely on your IDE/editor to spot type errors.

If your project already uses Webpack and you're satisfied with it, there's no reason to migrate to Vite. But if you're creating a new project, I highly recommend giving Vite a try.


Become a Better JavaScript Developer! My newsletter has easy, actionable steps to level up your JavaScript skills, right to your inbox. Click here to subscribe

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay