-
Notifications
You must be signed in to change notification settings - Fork 660
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
Setting a custom ASSET_URL works: