|
| 1 | +# NativePHP Build Fix Guide |
| 2 | + |
| 3 | +## Problem Summary |
| 4 | +When building the NativePHP/Electron app, frontend assets weren't being properly included, causing "Vite not found" errors on fresh installations. |
| 5 | + |
| 6 | +## Root Causes Identified |
| 7 | + |
| 8 | +1. **Hot Reload File**: The `public/hot` file was being included in builds, causing Laravel to look for Vite dev server |
| 9 | +2. **Missing npm install**: Build process wasn't installing npm dependencies before building |
| 10 | +3. **Build artifacts**: Development artifacts were interfering with production builds |
| 11 | + |
| 12 | +## Fixes Applied |
| 13 | + |
| 14 | +### 1. Updated `config/nativephp.php` |
| 15 | + |
| 16 | +- Added `public/hot` to `cleanup_exclude_files` to prevent it from being included in builds |
| 17 | +- Added `npm install --omit=dev` to prebuild commands before `npm run build` |
| 18 | + |
| 19 | +### 2. Created Build Preparation Script |
| 20 | + |
| 21 | +Created `build-prepare.sh` to ensure clean builds: |
| 22 | +- Removes development artifacts (hot file, .vite cache) |
| 23 | +- Installs production npm dependencies |
| 24 | +- Builds frontend assets |
| 25 | +- Verifies manifest.json exists |
| 26 | +- Optimizes Laravel for production |
| 27 | + |
| 28 | +## Build Process |
| 29 | + |
| 30 | +### For Development |
| 31 | +```bash |
| 32 | +# Start development environment |
| 33 | +composer dev |
| 34 | + |
| 35 | +# Or for NativePHP development |
| 36 | +composer native:dev |
| 37 | +``` |
| 38 | + |
| 39 | +### For Production Build |
| 40 | + |
| 41 | +1. **Prepare the build** (run this before building): |
| 42 | + ```bash |
| 43 | + ./build-prepare.sh |
| 44 | + ``` |
| 45 | + |
| 46 | +2. **Build the application**: |
| 47 | + ```bash |
| 48 | + php artisan native:build mac arm64 |
| 49 | + ``` |
| 50 | + |
| 51 | +3. **Test the build** on a fresh machine: |
| 52 | + - Copy the built app from `dist/` directory |
| 53 | + - Install and run - it should work without any Vite errors |
| 54 | + |
| 55 | +## Important Notes |
| 56 | + |
| 57 | +1. **Always run build-prepare.sh** before building for production |
| 58 | +2. **Never commit the `public/hot` file** to version control |
| 59 | +3. **Ensure `public/build/manifest.json` exists** after building |
| 60 | +4. The prebuild commands in `config/nativephp.php` will automatically: |
| 61 | + - Install npm dependencies |
| 62 | + - Build frontend assets |
| 63 | + - Optimize Laravel |
| 64 | + |
| 65 | +## Troubleshooting |
| 66 | + |
| 67 | +If you still see "Vite not found" errors: |
| 68 | + |
| 69 | +1. Check if `public/hot` file exists in the built app - it shouldn't |
| 70 | +2. Verify `public/build/manifest.json` exists in the built app |
| 71 | +3. Ensure the app is running in production mode (`APP_ENV=production`) |
| 72 | +4. Check Laravel logs for any asset-related errors |
| 73 | + |
| 74 | +## Testing on Fresh Machine |
| 75 | + |
| 76 | +When testing on a new machine: |
| 77 | +1. The app should work immediately after installation |
| 78 | +2. No need to run `npm install` or `npm run dev` |
| 79 | +3. All assets should be pre-built and included |
0 commit comments