Skip to content

Auto-configure Vite plugin during native:install#26

Open
benjam-es wants to merge 1 commit intoNativePHP:mainfrom
benjam-es:feature/auto-configure-vite-plugin-rebased
Open

Auto-configure Vite plugin during native:install#26
benjam-es wants to merge 1 commit intoNativePHP:mainfrom
benjam-es:feature/auto-configure-vite-plugin-rebased

Conversation

@benjam-es
Copy link

Summary

  • Automatically configure the nativephpMobile Vite plugin for Inertia (React/Vue) projects during native:install
  • Inject import, hotFile config, and nativephpMobile() into the user's vite config
  • Validate the modified config with node --check before overwriting
  • Fall back to manual instructions if auto-config can't be applied or user declines
  • Add --with-vite flag to skip the confirmation prompt

Test plan

  • 10 unit tests covering: skip conditions, injection, idempotency, decline path, temp file cleanup
  • PHPStan passes
  • Pint passes

Related

- 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
Copy link
Member

@simonhamp simonhamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

@benjam-es benjam-es left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants