Auto-configure Vite plugin during native:install#26
Auto-configure Vite plugin during native:install#26benjam-es wants to merge 1 commit intoNativePHP:mainfrom
Conversation
- Automatically set up the NativePHP Vite plugin for Inertia projects - Inject import, hotFile config, and nativephpMobile() into vite config - Validate modified config with node --check before overwriting - Fall back to friendly manual instructions if auto-config can't be applied - Add --with-vite flag to skip the confirmation prompt
simonhamp
left a comment
There was a problem hiding this comment.
I love the idea of this and it was something I was exploring when creating the Vite plugins, but using regex to modify the Vite config is super fragile
The better approach (which I didn't have time for) is a to use an AST to modify the existing code
But a simpler short-term solution is to just write a new pre-configured vite.config.js file
Or better yet build an app from our new starter kit in which it is already pre-configured
There was a problem hiding this comment.
Totally fair point on regex fragility in general — but I think the Laravel Vite config is a special case. It's essentially a template: short, predictable structure, and users rarely deviate much from what the starter gives them.
The current approach also has safety nets: it writes to a temp file, validates with node --check before overwriting, and falls back to manual instructions if anything goes wrong. So worst case, the user just gets told what to paste.
The AST route would mean either bundling a parser or adding a dependency — feels like a lot of overhead for modifying what's effectively a 15-line file.
Happy to explore writing a fresh config file instead if you'd prefer that, but wanted to make the case for keeping it simple.
Thoughts @simonhamp ?
Summary
nativephpMobileVite plugin for Inertia (React/Vue) projects duringnative:installhotFileconfig, andnativephpMobile()into the user's vite confignode --checkbefore overwriting--with-viteflag to skip the confirmation promptTest plan
Related