-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.x] Fix setting custom ASSET_URLs and support cache busting without integrity check #1427
[5.x] Fix setting custom ASSET_URLs and support cache busting without integrity check #1427
Conversation
…rity check Fixes laravel#1425 Fixes laravel#1426
Thanks for submitting a PR! Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
import { resolve } from "node:path"; | ||
import { readFileSync, writeFileSync } from "node:fs"; | ||
|
||
function manifestQueryParam() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This vite plugin aims to provide the same functionality of cache busting (with md5 hash route parameter) as laravel mix did instead of using integrity checks on the tags and passing the integrity key in the manifest.
<link rel="preload" as="style" href="{{ Vite::asset('resources/sass/styles.scss', 'vendor/horizon') }}" /> | ||
<link rel="stylesheet" href="{{ Vite::asset('resources/sass/styles.scss', 'vendor/horizon') }}" data-scheme="light" /> | ||
<link rel="preload" as="style" href="{{ Vite::asset('resources/sass/styles-dark.scss', 'vendor/horizon') }}" /> | ||
<link rel="stylesheet" href="{{ Vite::asset('resources/sass/styles-dark.scss', 'vendor/horizon') }}" data-scheme="dark" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Vite Helper doesn't support rendering css files with parameters. they need to end with .css/.less etc. thats why we need to handcraft this.
use Illuminate\Support\Facades\Vite; | ||
use Illuminate\Foundation\Vite as ViteFoundation; | ||
$nonExistentFileName = public_path('/vendor/horizon/nonExistentFile'); | ||
$previousHotFile = Vite::hotFile(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We save the previously detected hotfile of the user so we can reset the hotfile at the end of the blade template and "restore" the previous state.
Fixes #1425
Fixes #1426
There were already tries to integrate Vite with telescope which have been postponed because of the linked issues and other concerns. I think this PR now solves all of these issues.
@timacdonald I would love to hear your opinion as well as you were involved in a lot of these discussions as well:
--clean
option tovendor:publish
command framework#49329 (missing cleanup functionality for packages exporting vite files that include the file hash in the filename) because of this, we need to manually craft cache busting ids to the filename in the manifest instead of using the normal hashed files of vite e.g.app.129hg41.js
. Without the cleanup, users would end up with a lot of outdated files published by packages like laravel/horizon and laravel/telescopenpm run dev
commands which this version of the vite implementation resolvesalso related:
clean-orphaned-assets
binary vite-plugin#251 (cleanup on the javascript side for the laravel-vite-plugin)Screenshots:
Running vite dev mode renders the "none" vite url
![image](https://private-user-images.githubusercontent.com/10237069/325395405-5c41c0e8-89e3-403f-bac3-1edb36eca45e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYxMDI4OTIsIm5iZiI6MTcyNjEwMjU5MiwicGF0aCI6Ii8xMDIzNzA2OS8zMjUzOTU0MDUtNWM0MWMwZTgtODllMy00MDNmLWJhYzMtMWVkYjM2ZWNhNDVlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTEyVDAwNTYzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMxYTdhYWI4MWZkNWE4ZGUxM2Q1ZGUxZTJhZWIwNjc2NGI4YjcyN2NiOWVmNzI5NjkzNjNlMDQxNjMwNDkzYTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.VjsgOCDcvLydZRc_VlW7aCe5acB5NBA8H37HzMdz3UA)
Setting a custom ASSET_URL works: