This is how I set mine up. Lando is just an alternative to sail https://sinnbeck.dev/posts/getting-vite-and-laravel-to-work-with-lando
Jan 24, 2023
44
Level 1
Vite migration Not Connecting
Hello,
I am migrating an older laravel, vue, vuetify, and docker project from laravel mix to vite. I am able to successfully build with "vite" and "vite build". But the site is not refreshing.
Errors:
- In Console on login blade page:
- Page loads and looks normal
- url net::ERR_ADDRESS_INVALID
- url net::ERR_ADDRESS_INVALID
- url net::ERR_ABORTED 404
- it looks like these are coming from the vite directives in the blade
- Page loads and looks normal
- On SPA Page:
- nothing loads
- 500 Server Not Connecting
- or the last version of the site compiled using laravel mix
- nothing loads
Process/files/code
- I used laravel shift to add vite. (we are on laravel 9)
- We are serving the vue files from a blade. There are several blades. A few for login prompts and one for our site (besides logins we use vue router and have a Single Page Application)
- I added the vite directives to two of the blades (initial login blade and SPA blade)
- I deleted the mix scripts from the blades
- added vite port to docker-compose
vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue2';
import path from 'path';
import { VuetifyResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
export default defineConfig({
server: {
hmr: {
host: '0.0.0.0',
watch: {
usePolling: true,
},
},
},
plugins: [
laravel({
input: ['resources/sass/app.scss', 'resources/js/app.js'],
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
Components({
resolvers: [
VuetifyResolver(),
],
}),
],
resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
alias: {
'@': path.resolve(__dirname, './src'),
'~bootstrap': path.resolve(__dirname, 'node_modules/bootstrap'),
},
},
css: {
preprocessorOptions: {
sass: {
additionalData: [
'@import "./resources/sass/variables.scss"',
'@import "vuetify/src/styles/settings/_variables"',
'', // end with newline
].join('\n'),
},
},
},
});
Docker File two database containers ngingx container laravel application container
ports:
- '8080:80'
- '8843:443'
- '5173:5173'
Login Blade
<!-- cannot include links on first day signing up laracast -->
vite directives
vite directive script tags here
</head>
SPA Blade
<!-- cannot include links on first day signing up laracast -->
vite directives
vite directive script tags here
</head>
.env
APP_URL= http local host 8080 (cannot post links first day on laracast)
Thanks for the Help!
Please or to participate in this conversation.