-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.wails.plugin.ts
More file actions
31 lines (29 loc) · 1.21 KB
/
vite.wails.plugin.ts
File metadata and controls
31 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { Plugin } from 'vite';
export default function wailsPlugin(): Plugin {
return {
name: 'wails',
transformIndexHtml(html) {
// В продакшене Wails вставит свои скрипты через {{.WailsJS}},
// но в dev режиме мы должны вручную вставить скрипт для подключения к Wails
if (process.env.NODE_ENV === 'development') {
const wailsScript = `
<script>
// В dev режиме подключаемся к Wails серверу
const script = document.createElement('script');
script.src = 'http://localhost:34115/wails/runtime/runtime.js';
document.head.appendChild(script);
// Добавляем логирование для отладки
script.onload = function() {
console.log('Wails runtime script loaded successfully from plugin');
};
script.onerror = function() {
console.error('Failed to load Wails runtime script from plugin');
};
</script>
`;
return html.replace('</body>', `${wailsScript}\n </body>`);
}
return html;
}
};
}