-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
40 lines (37 loc) · 1.64 KB
/
Copy pathindex.html
File metadata and controls
40 lines (37 loc) · 1.64 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
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>SkyGit</title>
<link rel="icon" type="image/png" href="/images/favicon-32x32.png" />
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
<!-- Register the service worker using the correct base path both in dev ("/") and after
build/deploy (e.g. "/skygit/").
We rely on Vite to replace `import.meta.env.BASE_URL` with the proper value during the
build. Using a <script type="module"> block allows us to reference the ESM `import.meta`
object from within the HTML template. -->
<script type="module">
/*
Register the service-worker **only** for production builds.
During `vite dev` the generated `sw.js` file does not exist –
`vite-plugin-pwa` creates it only for production builds (or when
`devOptions.enabled` is explicitly set to `true`). Attempting to
register the worker in development therefore results in the dev
server returning the HTML fallback for `/sw.js`, which the browser
refuses to load because it has the wrong MIME type (text/html).
Guarding on `import.meta.env.PROD` avoids that situation while still
keeping the PWA behaviour in the built application.
*/
if (import.meta.env.PROD && 'serviceWorker' in navigator) {
const swUrl = `${import.meta.env.BASE_URL}sw.js`;
navigator.serviceWorker.register(swUrl, {
scope: import.meta.env.BASE_URL,
});
}
</script>
</body>
</html>