
Frontend Developer at Thoughtworks
Search for a command to run...

Frontend Developer at Thoughtworks
No comments yet. Be the first to comment.
Recently, I had the chance to work on SEO (Search Engine Optimization) for one of the projects. I learned a few things along the way. You can follow these steps: Google doesn’t accept any payment to make any website rank better, it all depends on the...

Micro interactions are common on most websites and mobile apps these days to enhance the user experience. I tried creating a simple micro interaction for my portfolio web app. While this could be done with CSS alone, but it is really complex. I found...

Story Behind the Blog Until recently, we managed all our form data using MobX. However, after introducing React Hook Form, form validation became much simpler. We realized that there was no need to save the form data in multiple places since React Ho...

Let's go through the steps to migrate your frontend repo to Vite

We have recently switched from parcel to Vite in one of my frontend projects(tech stack - Yarn Monorepos, React, Typescript, Styled Components, Jest, RTL). we were facing the problem of HMR since we were using mono repos, so decided to give a shot at vite and the results were incredible. Vite is fast!
Parcel is a zero-config tool. It simplifies the project setup at the cost of cache issues, poor HMR and slower build times. This problem will be more evident in bigger projects. I still recommend Parcel for people who are starting out new or don't want to worry about the project setup.
Vite - Speeds up the local build time.
Vite - HMR(hot module replacement) is incredibly fast. Loads the changes in no time. Vite internally uses Rollup as a bundler but they are planning to use esbuild in future which might make it even faster for production builds. Click to know more.
Positives
Seriously Zero Config. This is the tool you should go for if you are a newbie or don't want to scratch your head around project setup.
Great tooling support especially lint and typescript support.
Prod builds are equally fast as Vite.
Negatives
Cache issues especially when working with mono-repository.
HMR delay. Take a lot of time to reflect the changes on the browser which can be because of the cache it maintains. The browser gets into the loading state and never recovers from it, the only solution is to close the tab or restart the parcel build script.
Positives
Incredibly fast build times, especially local builds but comparatively prod build might take more time.
HMR works like a charm. The browser reflects the changes in no time. Hardly there are times when I have to go and refresh the page.
Negatives
Tooling support for lint and typescript is not that great as of now. I am using vite-plugin-checker for highlighting typescript issues.
Little Config overhead. It needs you to go through the docs to set up the project but I feel it's minimal. Far better than webpack config.
Changes are required for environment variables for eg. env variables are now exposed on import.meta.env and they have to be appended with VITE_ for it to be accessible in the project. Click here to know more. Jest test setup might start throwing errors because now the environment variables are not directly accessible on process object. But there is still a way to fix that by using the define attribute in vite.config.js . Click here to know more.
I will cover the setup part for React, Typescript, Jest + Vite in upcoming blog.
Feel free to share your thoughts in the comments.
Thanks for reading!