When using Vue 3 with Laravel Blade template, issues arise when trying to generate a production build

When working with Vue 3 SFC and trying to embed the template inside a Laravel Blade file, it can be a bit tricky. Take for example this usage scenario:

Test.vue

<script setup>

import { ref} from 'vue';

const testValue = ref('Works');

</script>

app.blade.php

<head>
    @stack('js')
</head>

<body>
    <div id="app">
        @yield('content')
    </div>
</body>

</html>

test.blade.php

@extends('layouts.app')
@push('js')
    @vite(['resources/js/test.js'])
@endpush
@section('content')
    <span>@{{ testValue }}</span>
@endsection

test.js

import { createApp } from 'vue';
import Test from "./components/Test.vue";
const app = createApp(Test).mount("#app");

Despite the complexity, using blade files seems to work well after running npm run dev:

https://i.stack.imgur.com/fK09m.png

However, once npm run build is executed, only a blank page appears without the blade file template being rendered:

https://i.stack.imgur.com/jD4qD.png

If you have any insights on why this might happen and how to resolve it, here's a glimpse at my configuration:

vite.js.config

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
        server: {
            hmr: true,
            https: false,
            host: 'localhost',
            proxy: {
                // Proxying websockets or socket.io
                '/app': {
                    target: 'wss://localhost:6001',
                    ws: true
                }
            }
        },
        plugins: [
            laravel(
                {
                    input: [
                        'resources/js/test.js',
                    ],
                    refresh: true,
                }),
            vue({
                template: {
                    transformAssetUrls: {
                        base: null,
                        includeAbsolute: false,
                    },
                },
            }),
        ],
        resolve: {
            alias: {
                'vue': 'vue/dist/vue.esm-bundler.js',
            },
        },
        build: {
            chunkSizeWarningLimit: 1000,
        },
        define: {
            __VUE_PROD_DEVTOOLS__: true,
            __VUE_OPTIONS_API__: true,
        }
    });

Answer №1

For optimal performance, make sure to relocate the @stack('js') code within your app.blade.php file to be within the body tags right before closing it.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error encountered while attempting to download PDF file (blob) using JavaScript

Recently, I have been utilizing a method to download PDF files from the server using Laravel 8 (API Sanctum) and Vue 3. In my Vue component, I have implemented a function that allows for file downloads. const onDownloadDocument = (id) => { ...

Using Angular and Laravel to display JSON data extracted from a MySQL database

I am currently retrieving data from MySQL using Laravel query builder, converting it to JSON format as per the suggestion of W3schools. However, when trying to display the fetched data using AngularJS, I end up with a blank page. Laravel route Route::ge ...

"Utilizing the power of PHP in Laravel's dynamic

My understanding of Laravel Blade is limited and I am struggling with the following code: <span v-bind:class="{ 'total': (listing.price_per_week), 'total total-center': (!listing.price_per_week)}">@{{ listing.price_view }}*</s ...

Laravel Error: Required parameters are missing for the specified route [editGallery] with URI [editGallery/{gallery_id}]

I'm encountering an issue with my code Here is the error I'm facing ErrorException in UrlGenerationException.php line 17: Missing required parameters for [Route: editGallery] [URI: editGallery/{gallery_id}]. (View: C:\xampp\htdocs&b ...

Retrieve the image URL from a Blue Prism Object Storage container by using a Node.js application

I currently have images stored in a container on my Object Storage instance in Bluemix. I am looking for a way to get the source URL for these images so that I can use them elsewhere. My plan is to create a Node.js application where I can make a post reque ...

What is the best way to remove an active item from a Vue v-list?

When using Vuetify's v-list-item directive, I encountered an issue where the active prop cannot be removed once an item has been selected. Here is my approach so far: <v-list-item-group pb-6 color="primary" class="pb-3 text-left"> ...

Comparing two timestamps to the current date in PHP using Laravel

Comparing two timestamps, starting_date and ending_date, with the current time is a necessity for me. I am trying to achieve the following: $discount_db = Discount::whereActive(1) ->where('starting_date', '<= ...

Vue: Applying a specific class to a single element in a v-for loop

When using a v-for loop to display a list of items, I have implemented a function triggered by @click that deletes the item. However, I want to add a temporary background color change upon clicking to indicate to the user that the deletion is in progress ...

What are the benefits of opting for <router-link> compared to using <a href="">?

When utilizing vue-router, the component known as <router-link> is available for linking to various routes. For instance: <router-link to="/foo">Link</router-link> Nevertheless, it appears that the subsequent code accomplishes a similar ...

Vuex has reserved this keyword

I am working on a Laravel application with the following code in app.js: require('./bootstrap'); window.Vue = require('vue'); import { store } from './store/store' import Sidebar from './Sidebar' Vue.component(& ...

What sets npm install apart from npm update?

Can you explain the real distinction between npm install and npm update? In what situations should I opt for each one? ...

What could be causing the EBUSY: resource busy or locked, open errno: -4082 error to appear while trying to build storybook 7 in next.js 13?

While attempting to create a storybook, I encountered the following error in my project: [Error: EBUSY: resource busy or locked, open 'C:\Users\ali\Desktop\Works\Design Systems\projects\storybook-test2\node_modu ...

Error occurred while installing PWA Studio due to incorrect package manager selected

Running yarn install (node -e 'process.env.CI||process.exit(1)' || npx npm-is yarn) on https://github.com/magento/pwa-studio.git throws an error: /Users/name/.npm/_npx/eb07260b9bcce2ea/node_modules/npm-is/npm-is.js:67 throw new WrongPackageMa ...

Could you offer guidance on incorporating a component into a Vue route?

I am attempting to integrate a vue component called <channel-card></channel-card> into my home route, but I am encountering multiple errors. Main.js const router = new VueRouter({ routes: [ {path: '/home', component: home} ] ...

Removing an element in Vue.js

Can someone help me with a Vue.js issue I'm having? I'm working on a quiz and I want to add a button that deletes a question when clicked. Here's what I've tried so far: deleteQuestion(index) { this.questions.splice(index, ...

Solve the mystery of hidden IP addresses in Node.js with the help of the DNS module

Is it possible to achieve the same result as running the command dns-sd -q a5b3ef18-2e66-4e24-91d2-893b93bbc1c1.local on Mac OSX using Node.js? It appears that the dns module in Node.js is primarily used for converting website addresses to IP addresses, no ...

Apologies, but the development JavaScript bundle could not be generated due to an unexpected token error with code #981

After cloning my repository and installing all packages via npm, I encountered an error when trying to start my program with gatsby develop. The error appears in all files within the templates directory. https://i.stack.imgur.com/MsAUm.png I've atte ...

Eliminate duplicate time slots in Laravel and Vuejs

Currently, I am delving into laravel(5.2) and vuejs as a newcomer to both frameworks. My goal is to utilize vuejs to eliminate redundant time slots. In my blade file, the code looks like this: <div class="form-group"> <label for="form-fi ...

Is it possible to include additional options in the dependencies section of npm package.json file?

I am facing an issue with the sqlite3 package dependency. Normally, when installing the sqlite3 package, it automatically downloads and uses a pre-packaged version of the sqlite3 engine. However, this can cause problems when working with sqlite3 extension ...

Issue with npm package installation causing malfunction

Upon running the command npm install -g lerna, it gets executed without any errors. However, when I try to run lerna --version, I receive an output stating "lerna: command not found". Potential Solution: Perhaps if I somehow manage to install it in / ...