-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[10.x] Add content
method to Vite
#47968
[10.x] Add content
method to Vite
#47968
Conversation
content
method to Vitecontent
method to Vite
This sounds pretty useful, and I've run into similar scenarios myself. My only concern is that the local dev behaviour might be unexpected or confusing when running the Vite dev server. It will fail if you haven't run a build since adding the asset. Otherwise, it will return the contents from the last build, ignoring any changes you've made to the source file. You'd need to run Vite in "watch" mode instead of HMR mode if you wanted to automatically have the latest changes while developing. |
Co-authored-by: Jess Archer <[email protected]>
@jessarcher what can we do to address this? Maybe adding an exception when in HMR and the method is called? By the way, developers can add a check like this: @if (! Vite::isRunningHot())
<style>{!! Vite::content('resources/scss/file.scss') !!}</style>
@else
@vite('resources/scss/file.scss')
@endif I thought also about adding the redirect to the |
@michael-rubel You could try calling It's probably fine as-is. Just a caveat to be aware of when using it. |
About
This PR adds a method to retrieve compiled content for the given file available in the Vite manifest. It allows us to pack our Vite assets inline when needed.
Example use case
You want to create an HTML page that needs to be open or sent as a single document (for example, as a mail attachment), and to work offline (without access to the internet) so the asset should be injected into the document for the browser to work on the local file without firing the HTTP requests.
Usage example