leaf icon indicating copy to clipboard operation
leaf copied to clipboard

LeafPHP MVC Error: Vite manifest not found at: /build/build/manifest.json, when trying to run with build in production mode

Open shashankitsoft opened this issue 2 years ago • 5 comments

Describe the bug Using leaf with MVC, created project using : leaf create <project-name> --mvc Windows 11, PHP 8.1, On command line, leaf --version = v2.11.1 As per composer json:

{ "leafs/leaf": "^3.3",
 "leafs/vite": "^0.1.0",
  "leafs/blade": "*",
   "leafs/mvc-core": "dev-main",
 ..
}

As per package.json:

"devDependencies": {
        "@leafphp/vite-plugin": "^0.1.2",
        "sass": "^1.69.5",
        "vite": "^4.4.9"
    },

Now leaf serve works fine and site visible on http://localhost:5500/ Creating a build using leaf view:build generate successfully. But on running leaf serve give error Error: Vite manifest not found at: /build/build/manifest.json

To Reproduce

  1. In default Leaf-MVC installation and added sass as above, create a css app\views\scss\test.css (having just one line css and an inner import of scss
@import './test-inner1.scss';
div{background-color: red !important;}

test-inner1.scss also has just div{color: green;}

  1. Go to app\views\index.blade.php and include that css in head, {{ vite('scss/test.css') }}
  2. In .env set, APP_ENV=production (earlier it was 'local')
  3. vite.config.js as below (just added css file name, rest as default):
import { defineConfig } from 'vite';
import leaf from '@leafphp/vite-plugin';

export default defineConfig({
    plugins: [
        leaf({
            input: ['app/views/js/app.js', 'app/views/css/app.css','app/views/scss/test.css'],
            refresh: true,
        }),
    ],
});
  1. Go to command line, creating a build using leaf view:build generate successfully. The files assets and manifest.json generated in correct folder paths:

public/build/manifest.json public/build/assets/app-e3b0c442.css public/build/assets/test-35007d2a.css public/build/assets/app-bc6e2fe4.js

  1. Now running leaf serve give error on http://localhost:5500/ Error: Vite manifest not found at: /build/build/manifest.json. This obviously it is searching in wrong path /build/build. The path where manifest generated was public/build .

error

The path of css included with vite function in app\views\index.blade.php i.e. {{ vite('scss/test.css') }} should be able to look for manifest in correct folder path, in production using build or normal development mode.

Or I am missing something? How I can write the css or js paths in blade templates, which work in dev as well as in production mode. I want to test both modes on localhost.

Expected behavior The css/js files included in blade templates should look for build manifest in correct path in production mode, and use normal/original paths in development mode (as build is not needed in dev mode)

How the css/js files to be included rightly with vite() in blade template head, to work in both modes? Will like to know if something I am missing here, or to be set differently, as I have not found related in documentation of Leaf.

shashankitsoft avatar Nov 22 '23 10:11 shashankitsoft