File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed
Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -24,16 +24,21 @@ public function __construct(
2424
2525 public function resolveTags (array $ entrypoints ): array
2626 {
27- return arr ($ entrypoints )
27+ $ tags = arr ($ entrypoints )
2828 ->map (function (string $ entrypoint ) {
2929 if (! Filesystem \exists ($ entrypoint ) && ! Filesystem \exists (root_path ($ entrypoint ))) {
3030 throw new FileSystemEntrypointWasNotFoundException ($ entrypoint );
3131 }
3232
3333 return $ this ->createDevelopmentTag ($ this ->fileToAssetPath ($ entrypoint ));
3434 })
35- ->prepend ($ this ->createDevelopmentTag (self ::CLIENT_SCRIPT_PATH ))
36- ->toArray ();
35+ ->prepend ($ this ->createDevelopmentTag (self ::CLIENT_SCRIPT_PATH ));
36+
37+ if ($ this ->bridgeFile ->needsReactRefresh ) {
38+ $ tags ->prepend ($ this ->createReactRefreshTag ());
39+ }
40+
41+ return $ tags ->toArray ();
3742 }
3843
3944 private function createDevelopmentTag (string $ path ): string
@@ -62,4 +67,17 @@ private function fileToAssetPath(string $file): string
6267 ->replaceStart (root_path (), '' )
6368 ->toString ();
6469 }
70+
71+ private function createReactRefreshTag (): string
72+ {
73+ return <<<HTML
74+ <script type="module">
75+ import RefreshRuntime from ' {$ this ->bridgeFile ->url }/@react-refresh'
76+ RefreshRuntime.injectIntoGlobalHook(window)
77+ window. \$RefreshReg$ = () => {}
78+ window. \$RefreshSig$ = () => (type) => type
79+ window.__vite_plugin_react_preamble_installed__ = true
80+ </script>
81+ HTML ;
82+ }
6583}
Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ private function getBridgeFile(): ViteBridgeFile
140140
141141 return static ::$ bridgeFile = new ViteBridgeFile (
142142 url: $ content ->get ('url ' ),
143+ needsReactRefresh: $ content ->get ('needsReactRefresh ' , false ),
143144 );
144145 }
145146
Original file line number Diff line number Diff line change 88{
99 public function __construct (
1010 public string $ url ,
11+ public bool $ needsReactRefresh = false ,
1112 ) {}
1213}
You can’t perform that action at this time.
0 commit comments