source mapping, dynanmic vite hmr server port

This commit is contained in:
2026-11-30 16:57:03 +01:00
parent 8a67ed3e24
commit 8ce5072022
9 changed files with 85 additions and 84 deletions
+24 -5
View File
@@ -7,11 +7,30 @@
function mathallo_page_attachments_alter(&$page) {
if (getenv('APP_ENV') === 'development') {
// $attachments['#attached']['html_head'][] = [['src' => 'http://localhost:5173/@vite/client', 'type' => 'module'],'vite-client'];
// $page['#attached']['library'][] = 'http://localhost:5173/@vite/client';
// $attachments['#attached']['html_head'][] = [['src' => 'http://localhost:5173/assets/js/main.js', 'type' => 'module'],'vite-main'];
// $page['#attached']['library'][] = 'http://localhost:5173/assets/js/main.js';
$page['#attached']['library'][] = 'mathallo/vitehmr';
// Port réel du dev server Vite, écrit par le plugin devPortFilePlugin
// (vite.config.js) dans .vite-dev-port
// (premier port libre à partir de 5173, strictPort: false) : permet de
// lancer plusieurs sites sur le même modèle de thème en même temps.
$port = (int) trim((string) @file_get_contents(__DIR__ . '/.vite-dev-port'));
if ($port <= 0) {
$port = 5173;
}
$page['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'script',
'#attributes' => ['type' => 'module', 'src' => "https://localhost:{$port}/@vite/client"],
],
'vite-client',
];
$page['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'script',
'#attributes' => ['type' => 'module', 'src' => "https://localhost:{$port}/assets/js/main.js"],
],
'vite-main',
];
}else{
$page['#attached']['library'][] = 'mathallo/global';
}