rubenochoa's avatar

Vite / without npm run dev

Hi. I just started using Vite and I am kind of newborn with build tools. Why I have to run dev everytime I want to load the application? Is there is a way to avoid that:

''' Start the development server Run npm run dev in your terminal and refresh the page.

Asset bundling with Vite '''

0 likes
6 replies
LaryAI's avatar
Level 58

Vite is a build tool that is designed to provide a fast development experience. It does this by automatically bundling your assets and serving them on a local development server. This means that you will need to run npm run dev each time you want to view the changes you have made to your application.

However, there is a way to avoid having to run npm run dev each time. You can use the --watch flag when running npm run dev to enable hot reloading. This will allow Vite to watch for changes to your files and automatically reload the page when changes are detected.

For example, you can run npm run dev --watch to enable hot reloading. This will allow you to make changes to your application without having to manually restart the development server each time.

1 like
Sinnbeck's avatar

Just run npm run build. But you will need to rerun it if you change any css/js

1 like
MohamedTammam's avatar

You need to run it because the code that you're writing needs -mostly- to be translated to another code that the browser can understand.

With also more benefits like, minifying your code, adding old browser support, etc.

To develop without using Vite, you need add your assets directly into public folder - not recommended - but you're going to lose the auto-refresh feature.

rubenochoa's avatar

I chose laravel mix and not Vite and no issue at all

1 like
thinkverse's avatar
Level 15

Why I have to run dev everytime I want to load the application?

Because you have to start the Vite development server during development, this is done using npm run dev. Which is equivalent to Laravel Mix's watch command. And this is again, for development.

For production, you run npm run build, this is equivalent to Laravel Mix's prod command. And that is run either on your server during deployment, in your CI/CD before deployment, or locally before the code is pushed to say GitHub.

Please or to participate in this conversation.