It looks like your Vite configuration is mostly correct, but there are a few things you can check and adjust to ensure that your development server is properly refreshing when you make changes to your Vue files.
-
Ensure Vite is running in development mode: Make sure you are running
npm run devand notnpm run build. Thenpm run devcommand should start the Vite development server, which watches for changes and updates the browser automatically. -
Check the
refreshoption: Therefreshoption in thelaravel-vite-pluginshould be set totrue, which you have done correctly. This should enable hot module replacement (HMR). -
Check your file paths: Ensure that the paths to your Vue files and other assets are correct. Sometimes incorrect paths can cause issues with file watching.
-
Check for errors in the console: Sometimes, errors in your Vue components or other JavaScript files can prevent HMR from working correctly. Check the browser console and terminal for any error messages.
-
Update Vite and plugins: Ensure you are using the latest versions of Vite and its plugins. Sometimes bugs are fixed in newer versions.
Here is a slightly adjusted version of your configuration with some additional comments:
import laravel from 'laravel-vite-plugin';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
build: {
outDir: '../../public/build-admin',
emptyOutDir: true,
manifest: "manifest.json",
},
plugins: [
laravel({
publicDirectory: '../../public',
buildDirectory: 'build-admin',
input: [
__dirname + '/resources/assets/css/app.css',
__dirname + '/resources/assets/js/app.js',
__dirname + '/resources/assets/js/app-edit-categories.js',
],
refresh: true, // This should enable HMR
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
}
}),
],
server: {
watch: {
usePolling: true, // This can help in some environments where file watching is unreliable
},
},
});
Additional Steps:
-
Check your
package.jsonscripts: Ensure that yourpackage.jsonhas the correct scripts for running the development server:"scripts": { "dev": "vite", "build": "vite build" } -
Run the development server: Make sure you are running the development server with:
npm run dev -
Check for Vite and plugin updates: Update your dependencies to the latest versions:
npm update -
Clear cache: Sometimes clearing the cache can help:
rm -rf node_modules/.vite
By following these steps and ensuring your configuration is correct, you should be able to get Vite to properly update your Vue files during development. If the problem persists, consider providing more details about your environment and any error messages you are seeing.