then in your mobile browser, go to ip4address:8000 (or whichever port your laravel is running on, after you type php artisan serve). Please note that the ip4 address can change over time!
If you get a blank screen, if possible it can be helpful to view error logs from another laptop
I had to remove the ‘hot’ file from public folder for it to work → note that live changes won’t show anymore, for that run npm run build or see below for instructions how to change vite.config
if you don’t have access, and are using xxamp, it can help to go to xampp, httpd.conf
find
<Directory "C:/xampp/htdocs">
and replace ‘require local’ with
Require all granted
If that’s not already set
solving cors acces policy error from copilot;
The error Access to script /@vite/client has been blocked by CORS policy
occurs because the browser is blocking the Vite HMR client due to a cross-origin request issue. This typically happens when the Vite dev server (http://192.168.2.12:5173
) is accessed from a different origin than the Laravel server (http://192.168.2.12:8000
).
Here’s how to fix it:
Add the cors
option to the server configuration in your vite.config.js file to allow cross-origin requests: from 'vite'; (Comment out the lines under server and replace with your own IP address).
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { svelte } from '@sveltejs/vite-plugin-svelte';
export default defineConfig({
plugins: [
laravel({
input: 'resources/js/app.js',
refresh: true,
}),
svelte(),
],
server: {
host: '0.0.0.0', // Allow access from other devices
port: 5173, // Default Vite port
strictPort: true, // Fail if the port is already in use
strictPort: true, // Fail if the port is already in use
cors: true, // Enable CORS
hmr: {
host: '192.168.X.XX', // Replace with your machine's local IP4 address, beware, this can change over time
},
},
optimizeDeps: {
exclude: ['js-big-decimal']
}
});
After making the above changes:
Stop both the Laravel and Vite dev servers.
Restart the Laravel server:
php artisan serve --host=0.0.0.0 --port=8000