ui: use vite

This commit is contained in:
undefined committed 2024-06-05 10:38:00 +08:00
1 parent 3a26cfbfe3
commit 54d440710b
15 files changed
+588 -31

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
import $ from 'jquery';
window.Hydro = {
extraPages: [],
components: {},
utils: {},
node_modules: {},
version: process.env.VERSION,
};
window.jQuery = $; // sticky-kit require this
window.externalModules = {};
window.lazyModuleResolver = {};
console.log(
'%c%s%c%s',
'color:red;font-size:24px;',
' Welcome to\n',
'color:blue;font-weight:bold;',
`\
__ __ __
/ / / /_ ______/ /________
/ /_/ / / / / __ / ___/ __ \\
/ __ / /_/ / /_/ / / / /_/ /
/_/ /_/\\__, /\\__,_/_/ \\____/
/____/
`,
);
window.UiContext = JSON.parse(window.UiContext);
window.UserContext = JSON.parse(window.UserContext);
try { __webpack_public_path__ = UiContext.cdn_prefix; } catch (e) { }
if ('serviceWorker' in navigator) {
const encodedConfig = encodeURIComponent(JSON.stringify(UiContext.SWConfig));
const dev = process.env.NODE_ENV === 'development';
navigator.serviceWorker.register(
dev ? '/dev-sw.js?dev-sw' : `/sw.js?config=${encodedConfig}`,
{ scope: '/', type: dev ? 'module' : 'classic' },
).then((registration) => {
console.log('SW registered: ', registration);
}).catch((registrationError) => {
console.log('SW registration failed: ', registrationError);
});
}
const PageLoader = '<div class="page-loader nojs--hide" style="display:none;"><div class="loader"></div></div>';
$('body').prepend(PageLoader);
$('.page-loader').fadeIn(500);
const prefetch = Promise.all([
fetch(`/constant/${UiContext.constantVersion}.js`).then((r) => r.text()),
import('./api'),
]);
document.addEventListener('DOMContentLoaded', async () => {
Object.assign(window.UiContext, JSON.parse(window.UiContextNew));
Object.assign(window.UserContext, JSON.parse(window.UserContextNew));
const [data, HydroExports] = await prefetch;
Object.assign(window, { HydroExports });
eval(data); // eslint-disable-line no-eval
await HydroExports.initPageLoader();
}, false);