-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
[2.x] Add Vite Realtime Compiler integration for HMR #2016
Merged
Merged
Changes from 49 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
2f9ad79
Create Vite.php
caendesilva e3dc0a2
Create ViteFacadeTest.php
caendesilva 8aba46b
Create Vite server configuration
caendesilva 220fceb
Draft Vite option for the serve command
caendesilva d67c699
Improve realtime compiler documentation
caendesilva 851421d
Method to print the Vite message
caendesilva d2afcea
Run processes in parallel
caendesilva 6ad2b04
Stream both process outputs
caendesilva b6361ab
Create vite-index-page.html
caendesilva c87203a
Render Vite index page
caendesilva ed2404d
Draft facade methods
caendesilva f5d6c84
Alias Vite facade
caendesilva e59cecf
Add strict types declaration
caendesilva 93bfbbc
Implement the Vite asset method
caendesilva 2683f86
Serve Vite assets when running
caendesilva 58a7f7a
Implement the Vite connection checker
caendesilva 86e0180
Use much faster environment variable for Vite status
caendesilva b083300
Flush output
caendesilva da82fa6
Start over with Vite server
caendesilva 310407e
Simpler Vite process handler
caendesilva d0fc208
Run server asynchronously
caendesilva b6d96c4
Sleep while server is running
caendesilva 6d40de6
Handle output from sleep loop
caendesilva 6ea538f
Declare properties
caendesilva 6a19d1f
Type against the contract
caendesilva f170366
Sleep for 100ms instead of 1 second
caendesilva d935511
Remove unused Vite start message helper
caendesilva 406e8ae
Add Vite information to output start message
caendesilva 8419a68
Support standalone Vite servers
caendesilva 57a22d9
Use default Vite port
caendesilva f1c421e
Add widths for layout to work without network
caendesilva c0d67ff
Update tests for asynchronous server process
caendesilva 704f67c
Use the sleep facade
caendesilva b03ec7f
Add tests to cover introduced code
caendesilva 2208e17
Suppress failed connection warnings
caendesilva 761d92a
Update Vite server to check if the port is free
caendesilva deb202c
Conditionally write output
caendesilva 41a79fe
Document Windows performance
caendesilva 0daac5a
Document Windows issue
caendesilva 91297e8
Update RELEASE_NOTES.md
caendesilva 3687cea
Merge branch 'new-asset-system' into vite-integration
caendesilva fa4a631
Merge branch 'new-asset-system' into vite-integration
caendesilva 2e7f526
Merge branch 'new-asset-system' into vite-integration
caendesilva ff1f6dc
Fix unintentional change
caendesilva 0da73bf
Fix formatting
caendesilva 9dc44d1
Normalize formatting
caendesilva 5ed9f6b
Update RELEASE_NOTES.md
caendesilva e26941d
Mark feature as experimental
caendesilva 2a480c2
Add Vite HMR support for the app scripts
caendesilva 313e605
Update _ide_helper.php
caendesilva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,22 @@ | |
<style>[x-cloak] {display: none!important}</style> | ||
|
||
{{-- The compiled Tailwind/App styles --}} | ||
@if(config('hyde.load_app_styles_from_cdn', false)) | ||
<link rel="stylesheet" href="{{ HydeFront::cdnLink('app.css') }}"> | ||
@elseif(Asset::exists('app.css')) | ||
<link rel="stylesheet" href="{{ Asset::get('app.css') }}"> | ||
@endif | ||
@if(Vite::running()) | ||
{{ Vite::assets(['resources/assets/app.css']) }} | ||
caendesilva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@else | ||
@if(config('hyde.load_app_styles_from_cdn', false)) | ||
<link rel="stylesheet" href="{{ HydeFront::cdnLink('app.css') }}"> | ||
@elseif(Asset::exists('app.css')) | ||
<link rel="stylesheet" href="{{ Asset::get('app.css') }}"> | ||
@endif | ||
|
||
Comment on lines
+7
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make more sense if we just automatically enabled Vite when using |
||
|
||
{{-- Dynamic TailwindCSS Play CDN --}} | ||
@if(config('hyde.use_play_cdn', false)) | ||
<script src="https://cdn.tailwindcss.com?plugins=typography"></script> | ||
<script>tailwind.config = { {!! HydeFront::injectTailwindConfig() !!} }</script> | ||
<script>console.warn('The HydePHP TailwindCSS Play CDN is enabled. This is for development purposes only and should not be used in production.', 'See https://hydephp.com/docs/1.x/managing-assets');</script> | ||
{{-- Dynamic TailwindCSS Play CDN --}} | ||
@if(config('hyde.use_play_cdn', false)) | ||
<script src="https://cdn.tailwindcss.com?plugins=typography"></script> | ||
<script>tailwind.config = { {!! HydeFront::injectTailwindConfig() !!} }</script> | ||
<script>console.warn('The HydePHP TailwindCSS Play CDN is enabled. This is for development purposes only and should not be used in production.', 'See https://hydephp.com/docs/1.x/managing-assets');</script> | ||
@endif | ||
@endif | ||
|
||
{{-- Add any extra styles to include after the others --}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hyde\Facades; | ||
|
||
use Illuminate\Support\HtmlString; | ||
|
||
/** | ||
* Vite facade for handling Vite-related operations. | ||
*/ | ||
class Vite | ||
{ | ||
public static function running(): bool | ||
{ | ||
// Check if Vite was enabled via the serve command | ||
if (env('HYDE_SERVER_VITE') === 'enabled') { | ||
return true; | ||
} | ||
|
||
// Check if Vite dev server is running by attempting to connect to it | ||
// Todo: Improve performance on Windows (takes less than 1ms on macOS, but around 100ms on Windows) | ||
set_error_handler(fn () => false); // Todo: This warning surpressor does not work on Windows | ||
$server = fsockopen('localhost', 5173, $errno, $errstr, 0.1); | ||
restore_error_handler(); | ||
|
||
if ($server) { | ||
fclose($server); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static function assets(array $paths): HtmlString | ||
{ | ||
$html = sprintf('<script src="http://localhost:5173/@vite/client" type="module"></script>'); | ||
|
||
foreach ($paths as $path) { | ||
if (str_ends_with($path, '.css')) { | ||
$html .= sprintf('<link rel="stylesheet" href="http://localhost:5173/%s">', $path); | ||
} | ||
|
||
if (str_ends_with($path, '.js')) { | ||
$html .= sprintf('<script src="http://localhost:5173/%s" type="module"></script>', $path); | ||
} | ||
} | ||
|
||
return new HtmlString($html); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
May make more sense to have this alongside the CSS include since the script is deferred anyways, but not sure how to handle that best with the partials since it would fit better in the
head
component, and don't want to make such a big change here.