Did you ever figure this out?
Vite build for production not working with inertia and Vue 2
Allright, I'll try to be as thorough as possible so this will be a long one...
- Node 16.16.0
- Npm 8.11.0
- Php 8.1
- Laravel 9
- Inertia
- Vue 2
For development is all good. We run npm run dev and php artisan serve and the application works without any issues (http://localhost:8000 in this case)
Then we run npm run build and bunch of public/build/assets are generated, the manifest.json too. There are no errors, just a warning about some chunk larger than 500kb
But we serve the app with apache and it doesn't work. The console on firefox shows something like this:
Navega a http://sgc.staging:8080/login
GET http://sgc.staging:8080/login [HTTP/1.1 200 OK 2066ms]
GET http://sgc.staging:8080/build/assets/app.4fb56957.css [HTTP/1.1 200 OK 1ms]
GET http://sgc.staging:8080/build/assets/app.e809327a.css [HTTP/1.1 200 OK 6ms]
GET http://sgc.staging:8080/build/assets/app.503a19f2.js [HTTP/1.1 200 OK 49ms]
GET http://sgc.staging:8080/build/assets/Login.8e343736.css [HTTP/1.1 200 OK 0ms]
GET http://sgc.staging:8080/build/assets/Login.9cdcc92f.js [HTTP/1.1 200 OK 1ms]
GET http://sgc.staging:8080/favicon.ico [HTTP/1.1 200 OK 1ms]
GET http://sgc.staging:8080/build/assets/vueComponentNormalizer.9ef17bb1.js [HTTP/1.1 200 OK 1ms]
TypeError: $7.observable is not a function app.503a19f2.js:5:24793
A few other nonsensical js errors and that's it. Just a blank screen. No 404s of any kind. It seems those assets aren't build the right way. Also, if we open a shell and run npm run dev that staging site works.
- vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { createVuePlugin } from 'vite-plugin-vue2'
export default defineConfig({
plugins: [
laravel({
input: [
'resources/js/app.js',
],
refresh: true,
}),
createVuePlugin(),
],
});
- package.json
{
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"laravel-vite-plugin": "^0.5.0",
"postcss": "^8.1.14",
"vite": "^3.0.0",
"vite-plugin-vue2": "^2.0.2"
},
"dependencies": {
"@inertiajs/inertia": "^0.11.0",
"@inertiajs/inertia-vue": "^0.8.0",
"@inertiajs/progress": "^0.2.7",
"lodash": "^4.17.19",
"axios": "^0.27",
"bootstrap": "^4.6.2",
"bootstrap-vue": "^2.22.0",
"vue": "^2.7.8",
"vue-template-compiler": "^2.7.8"
}
}
- app.js
import './bootstrap.js';
import Vue from 'vue'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
import '../css/app.css';
import { createInertiaApp } from '@inertiajs/inertia-vue'
import { InertiaProgress } from '@inertiajs/progress'
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { BootstrapVue } from 'bootstrap-vue';
Vue.use(BootstrapVue);
Vue.prototype.$route = route;
createInertiaApp({
resolve: async (name) => {
let page = await resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue'));
return page;
},
setup({ el, App, props, plugin }) {
Vue.use(plugin)
new Vue({
render: h => h(App, props),
}).$mount(el)
},
})
InertiaProgress.init({
color: 'blue',
showSpinner: true,
});
I imagine it has something to do with the plugin for vue 2 and/or options to make the build.
I also used a different plugin "@vitejs/plugin-vue2": "^1.1.2", but same story, all good for development, but no luck using the static build....
I would appreciate any help.
Please or to participate in this conversation.