DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • PWA on iOS, Part 4: What Add to Home Screen Really Does
  • PWA on iOS, Part 3: Chrome on iPhone Is WebKit Too. How One Engine Sets the Rules for PWAs on iOS
  • Running a Self-Hosted WAF in Production: Practical Lessons From SafeLine
  • When Angular APIs Return 200 but the Frontend Is Already Failing Users

Trending

  • Vapi vs Retell AI vs LiveKit: Architecture, Latency, Pricing, and Developer Experience
  • Process Intelligence Landscape 2026: Mining, Orchestration, and the Agentic AI Shift
  • Observability With AI SREs: A 4-Step Implementation Guide
  • Getting Started With Qdrant: Building Intelligent Search Applications With Java

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Languages
  4. How To Make Vite Hot Module Replacement Work on Windows

How To Make Vite Hot Module Replacement Work on Windows

In this article, I will explain why we decided to leave Webpack and embrace Vite as assets build tool and Hot Module Replacement.

By 
Valerio Barbera
·
Feb. 18, 23 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
5.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

As many of my followers already know, we recently started the renovation of the Inspector dashboard UI with a fresh new design and a modern technology stack. In this article, I will explain why we decided to leave Webpack and embrace Vite as assets build tool and Hot Module Replacement. I will show you how to use HMR (hot module replacement) on Windows working with a VM as a development environment.

Since we use Laravel Homestead as a development machine, we struggled a bit to figure out how to properly use this new front-end development environment.

Let me start with a bit of context.

Vite vs. Webpack

Webpack rebuilds the entire application when you save a file. This is why the change can take some time to be reflected in the browser, even with HMR enabled. The slow feedback loop caused by Webpack creates a bad developer experience for developers working on mid to large-scale JavaScript applications.

Webpack bundle-based dev build

Vite instead leverages two improvements made recently in the JavaScript ecosystem to offer a better developer experience: the availability of ES Modules in the browser and compile-to-native bundler tools like esbuild.

The availability of ES Modules in the browser allows you to run a JavaScript application on the browser without having to bundle them together.

The core idea of Vite is to separate your Javascript application into two categories: 

  1. All the dependencies loaded from the node_modules directory. Pretty much everything is listed in the package.json file.
  2. Your application code. Modules that you write for your application often involve .js, .jsx, .vue, or .scss files.

While a bundler-based workflow like Webpack will have to process your entire JavaScript modules before a single browser request, Vite only processes your dependency modules before a single browser request.

Your application modules will be transformed and served by Vite when they are required by your application. Literally on the fly:

Vite ESM-based dev build

This is why Vite is able to process your development build faster than Webpack.

Another characteristic that I appreciate is that the entire environment requires very little configuration. You have to place a vite.config.js file in your project root folder. It requires very few options to be ready to go, and everything else is well-documented.

Vite Dev Server in Action

I noticed this different behavior opening the Chrome developer tool and navigating my application:

Vite dev server in action

As you can see, Vite serves all the application components separately, not a single bundle, as was the case with webpack.

This makes the first load in the browser a bit slow, but it makes the hot module replacement really fast, or even incredibly fast. Because it only loads the ES modules it needs when they are needed.

Hot Module Replacement

Hot Module Replacement (HMR) exchanges, adds or removes modules while an application is running without a full reload. This can significantly speed up development in a few ways:

  • Retain the application state which is lost during a full reload.
  • Save valuable development time by only updating what’s changed.
  • Instantly update the browser when modifications are made to CSS/JS in the source code, which is almost comparable to changing styles directly in the browser’s dev tools.

Here is an example of HMR in action during the development of our Sign-In page:

How To Use Hmr Working With VM as a Local Environment

With webpack we used to work by running all the commands directly inside the Homestead VM.

But running the Vite dev server (npm run dev) caused the HMR not to work.

The problem is not the virtualized environment per-se. But the virtualized environment is on top of a Windows machine. This is because of the way WSL (Windows Subsystem for Linux) currently works with the Windows file system. The workaround is to use usePolling option in the Vite config file:

JavaScript
 
export default defineConfig({
  plugins: [vue()],
  server: {
    watch: {
      usePolling: true
    }
  }
});

Consider that this option implies high CPU usage.

You can find a detailed description of how this option works in the documentation.

Updating the browser after a file change is not as immediate as one would like. But it works.

How To Fix the HMR Issue

The solution is to run the Vite dev server in your windows terminal outside of the Homestead VM. I think the problem should be the same for other virtualized environments like Docker.

Remember, you have to run the Windows terminal with admin permission. Otherwise, you will get a permission denied error.

Permission denied error

Running the command line with admin permissions, the server will start as expected, and you can enjoy the HMR during UI development. 

result after running the command line

Conclusion

Every new tool needs to be studied and adapted to our development environment. I hope this tutorial helped you better understand what Vite is and how it improves the developer experience compared to other technologies used so far.

CSS Google Chrome HTTPS JavaScript UI application Microsoft Windows

Published at DZone with permission of Valerio Barbera. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • PWA on iOS, Part 4: What Add to Home Screen Really Does
  • PWA on iOS, Part 3: Chrome on iPhone Is WebKit Too. How One Engine Sets the Rules for PWAs on iOS
  • Running a Self-Hosted WAF in Production: Practical Lessons From SafeLine
  • When Angular APIs Return 200 but the Frontend Is Already Failing Users

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook