Skip to content

Commit d7f5f93

Browse files
committed
fix: resolve NativePHP build issues with frontend assets
- Add public/hot to cleanup_exclude_files to prevent Vite dev mode in production - Add npm install step before npm run build in prebuild commands - Create build-prepare.sh script for clean production builds - Add comprehensive build fix documentation This ensures frontend assets are properly built and included when distributing the NativePHP application, fixing "Vite not found" errors on fresh installations.
1 parent 698624a commit d7f5f93

File tree

3 files changed

+122
-1
lines changed

3 files changed

+122
-1
lines changed

NATIVEPHP_BUILD_FIX.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

build-prepare.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
echo "🚀 Preparing Clueless for production build..."
4+
5+
# Remove any development artifacts
6+
echo "📧 Cleaning development artifacts..."
7+
rm -f public/hot
8+
rm -rf node_modules/.vite
9+
10+
# Install dependencies
11+
echo "📦 Installing npm dependencies..."
12+
npm install --omit=dev
13+
14+
# Build frontend assets
15+
echo "🏗️ Building frontend assets..."
16+
npm run build
17+
18+
# Verify build output
19+
if [ -f "public/build/manifest.json" ]; then
20+
echo "✅ Frontend assets built successfully"
21+
echo "📁 Build manifest found at: public/build/manifest.json"
22+
else
23+
echo "❌ Build failed - manifest.json not found"
24+
exit 1
25+
fi
26+
27+
# Clear and optimize Laravel
28+
echo "🔧 Optimizing Laravel..."
29+
php artisan config:clear
30+
php artisan route:clear
31+
php artisan view:clear
32+
php artisan cache:clear
33+
34+
# Cache for production
35+
php artisan config:cache
36+
php artisan route:cache
37+
php artisan view:cache
38+
php artisan optimize
39+
40+
echo "✨ Build preparation complete!"

config/nativephp.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
'content',
8484
'node_modules',
8585
'*/tests',
86+
'public/hot', // Remove Vite hot reload file in production
8687
// Don't exclude the build directory as it contains our native executable
8788
],
8889

@@ -153,7 +154,8 @@
153154
*/
154155
'prebuild' => [
155156
'./build-swift-audio.sh',
156-
'npm run build',
157+
'npm install --omit=dev', // Install production dependencies
158+
'npm run build', // Build frontend assets
157159
'php artisan optimize',
158160
'php artisan config:cache',
159161
'php artisan route:cache',

0 commit comments

Comments
 (0)