-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use
swDest
folder to resolve mjs and map files in Vite build (#…
…661)
- Loading branch information
Showing
12 changed files
with
327 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ node_modules | |
.DS_Store | ||
dist | ||
dev-dist | ||
dist-examples-root | ||
# intellij stuff | ||
.idea/ | ||
# routify | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="icon" href="/favicon.svg" type="image/svg+xml"> | ||
<link rel="apple-touch-icon" href="/pwa-192x192.png"> | ||
<link rel="mask-icon" href="/favicon.svg" color="#FFFFFF"> | ||
<meta name="msapplication-TileColor" content="#FFFFFF"> | ||
<meta name="theme-color" content="#ffffff"> | ||
<title>Vite App</title> | ||
<style> | ||
#app { | ||
text-align: center; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "vanilla-js-custom-sw", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"build-on-root": "vite build --outDir=../../dist-examples-root", | ||
"preview": "vite preview" | ||
}, | ||
"devDependencies": { | ||
"vite": "^5.0.0", | ||
"vite-plugin-pwa": "workspace:*", | ||
"workbox-cacheable-response": "^7.0.0", | ||
"workbox-core": "^7.0.0", | ||
"workbox-expiration": "^7.0.0", | ||
"workbox-routing": "^7.0.0", | ||
"workbox-strategies": "^7.0.0", | ||
"workbox-window": "^7.0.0" | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// <reference lib="webworker" /> | ||
import { cleanupOutdatedCaches, createHandlerBoundToURL, precacheAndRoute } from 'workbox-precaching' | ||
import { clientsClaim } from 'workbox-core' | ||
import { NavigationRoute, registerRoute } from 'workbox-routing' | ||
|
||
// self.__WB_MANIFEST is default injection point | ||
precacheAndRoute(self.__WB_MANIFEST) | ||
|
||
// clean old assets | ||
cleanupOutdatedCaches() | ||
|
||
/** @type {RegExp[] | undefined} */ | ||
let allowlist | ||
if (import.meta.env.DEV) | ||
allowlist = [/^\/$/] | ||
|
||
// to allow work offline | ||
registerRoute(new NavigationRoute( | ||
createHandlerBoundToURL('index.html'), | ||
{ allowlist }, | ||
)) | ||
|
||
self.skipWaiting() | ||
clientsClaim() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { pwaInfo } from 'virtual:pwa-info' | ||
import { registerSW } from 'virtual:pwa-register' | ||
|
||
const date = __DATE__ | ||
|
||
console.log(pwaInfo) | ||
|
||
const app = document.querySelector('#app') | ||
|
||
app.innerHTML = ` | ||
<div> | ||
<img src="/favicon.svg" alt="PWA Logo" width="60" height="60"> | ||
<h1>Vite + Vanilla JavaScript Custom Service Worker</h1> | ||
<br/> | ||
<p>${date}</p> | ||
<br/> | ||
</div> | ||
` | ||
|
||
registerSW({ | ||
immediate: true, | ||
onNeedRefresh() { | ||
console.log('onNeedRefresh message should not appear') | ||
}, | ||
onOfflineReady() { | ||
console.log('onOfflineReady message should not appear') | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { defineConfig } from 'vite' | ||
import { VitePWA } from 'vite-plugin-pwa' | ||
|
||
export default defineConfig({ | ||
mode: 'development', | ||
logLevel: 'info', | ||
define: { | ||
__DATE__: `'${new Date().toISOString()}'`, | ||
}, | ||
build: { | ||
sourcemap: true, | ||
}, | ||
plugins: [ | ||
VitePWA({ | ||
mode: 'development', | ||
base: '/', | ||
strategies: 'injectManifest', | ||
srcDir: './service-worker', | ||
filename: 'sw.js', | ||
includeAssets: ['favicon.svg'], | ||
injectRegister: false, | ||
injectManifest: { | ||
minify: false, | ||
enableWorkboxModulesLogs: true, | ||
}, | ||
manifest: { | ||
name: 'PWA Router', | ||
short_name: 'PWA Router', | ||
theme_color: '#ffffff', | ||
icons: [ | ||
{ | ||
src: 'pwa-192x192.png', // <== don't add slash, for testing | ||
sizes: '192x192', | ||
type: 'image/png', | ||
}, | ||
{ | ||
src: '/pwa-512x512.png', // <== don't remove slash, for testing | ||
sizes: '512x512', | ||
type: 'image/png', | ||
}, | ||
{ | ||
src: 'pwa-512x512.png', // <== don't add slash, for testing | ||
sizes: '512x512', | ||
type: 'image/png', | ||
purpose: 'any maskable', | ||
}, | ||
], | ||
}, | ||
devOptions: { | ||
enabled: true, | ||
/* when using generateSW the PWA plugin will switch to classic */ | ||
navigateFallback: 'index.html', | ||
suppressWarnings: true, | ||
type: 'module', | ||
}, | ||
}), | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters