question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blade @vite directive not detecting public/build Folder

See original GitHub issue
  • Laravel Vite Plugin Version: ^0.4.0
  • Laravel Version: ^9.19.0
  • Node Version: 18.6.0
  • NPM Version: 8.13.2
  • Host operating system: macOS 10.15.7
  • Web Browser & Version: Chrome 104.0.5112.48
  • Running in Sail / Docker: No

Description: Running npm run dev works well but when I run npm run build, the build folder is created as expected in public/build but the @vite direction in blade isn’t picking up the build folder at all. It keeps looking for @vite/client even though it is no longer in dev mode.

Screen Shot 2022-07-15 at 3 02 26 PM

Steps To Reproduce:

  1. Run npm run build after installing all the packages.
  2. In the main blade entry file, add @vite(['resources/js/app.js']) (I tried adding the build directory too @vite(['resources/js/app.js'], 'build') and that didn’t work)
  3. Visit the site in the browser and it should fail showing an net::ERR_CONNECTION_REFUSED in console.

This is my vite.config.js file:

import { defineConfig } from "vite";
import fs from "fs";
import { homedir } from "os";
import laravel from "laravel-vite-plugin";
import { resolve } from "path";
import vue from "@vitejs/plugin-vue";

let host = "stats.test";
export default defineConfig({
    plugins: [
        laravel("resources/js/app.js"),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
    ],
    resolve: {
        alias: {
            src: resolve(__dirname, "resources/js"),
            modules: resolve(__dirname, "resources/js/components/modules"),
            frontend: resolve(__dirname, "resources/js/components/frontend"),
            vendor: resolve(__dirname, "resources/js/vendor"),
            lang: resolve(__dirname, "resources/languages"),
        },
    },
    server: detectServerConfig(host),
});

function detectServerConfig(host) {
    let keyPath = resolve(homedir(), `.config/valet/Certificates/${host}.key`);
    let certPath = resolve(homedir(), `.config/valet/Certificates/${host}.crt`);

    if (!fs.existsSync(keyPath)) {
        return {};
    }

    if (!fs.existsSync(certPath)) {
        return {};
    }

    return {
        hmr: { host },
        host,
        https: {
            key: fs.readFileSync(keyPath),
            cert: fs.readFileSync(certPath),
        },
    };
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
timacdonaldcommented, Jul 16, 2022

This will happen if the public/hot file still exists.

check that you haven’t accidentally committed this file to the project repository. If it exists, delete it.

The plug-in should automatically delete it when it shuts down the HMR server, but potentially you committed the file while it was running.

If that isn’t the case, let us know.

1reaction
haleyngonadicommented, Jul 19, 2022

@timacdonald It’s in my .gitignore file for sure (from my laravel mix days) but I usually run build locally and push build files to my prod server.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel Vite Deploying to Host - Laracasts
It exported css and javascript to public/build folder. ... Now in my blade view, I call the @vite directive with the input file...
Read more >
Why Laravel Vite Directive Not Working in My Project?
Then this new blade directive must work properly. ... These can be found in the resources/views/components folder of your app.
Read more >
vite-plugin/UPGRADE.md at main · laravel/vite-plugin - GitHub
When using Vite, you will need to use the @vite Blade directive instead of the mix() helper. This will automatically detect whether you...
Read more >
Asset Bundling (Vite) - The PHP Framework For Web Artisans
Laravel integrates seamlessly with Vite by providing an official plugin and Blade directive to load your assets for development and production. Are you...
Read more >
laravel vite manifest not found at - You.com | The AI Search ...
It turns out the files in /public/build folder are not committed in the git repository, thus missing on production server. Should I? Install...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found