I want not to do any of the following:
- Commit compiled files to git (the route helper returns absolute URLs with your APP_URL leading the way).
- Call any other methods Ziggy’s route helper provides.
Thankfully, configuring things as I prefer is fairly straightforward. All I did was:
- update my node scripts to use Ziggy’s Artisan command,
- add the output file to my .gitignore, and
- define my own route helper that relies on Ziggy’s.
1. Tweak yer scripts.
Laravel’s default package.json looks something like this:
2. Withhold attention.
3. Tell that route helper what’s up.
The generated routes.js exports the routes in an object named Ziggy, which is what we’re importing on line 2 and passing as the 4th argument to ZiggyRoute(). The third argument tells Ziggy whether to use absolute URLs.
In app.js, I can just drop import 'global-helpers'; in and call my stripped-down route helper anywhere.
NOTE: I’ve got this in my webpack.mix.js (lets me import from vendor):
If you run into snags with ESLint or Jest, hit me up and I can share more of the less-directly-relevant setup.