LeafPHP MVC Error: Vite manifest not found at: /build/build/manifest.json, when trying to run with build in production mode
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
- 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;}
- Go to app\views\index.blade.php and include that css in head,
{{ vite('scss/test.css') }} - In .env set, APP_ENV=production (earlier it was 'local')
- 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,
}),
],
});
- Go to command line, creating a build using
leaf view:buildgenerate 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
- Now running
leaf servegive 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 .
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.