source mapping, dynanmic vite hmr server port
This commit is contained in:
@@ -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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user