-
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add experimental PWA assets generation and injection (#621)
* feat: pwa assets generation and injection * chore: update logic for assets 0.2.1 * chore: load assets generator when assets configured * chore: refactor `ResolvedIconAsset` * chore: cleanup assets entry from jsdocs * chore: remove cache control cache * chore: refactor assets loader logic * chore: include pwa assets reload support * chore: include test with png image * chore: early return if url is not an image * chore: use test in early return if url is not an image * chore: use any for PWA assets generator (+ jsdocs) * chore: refactor html injection * chore: use any for `lookupPWAAssetsInstructions` * chore: generate assets only when pwa enabled * chore: refactor helper functions * chore: return if missing icon asset * chore: refactor assets generator * chore: vite base can be empty * chore: change logic for overrideManifestIcons * chore: update logic for overrideManifestIcons * chore: update hint for overrideManifestIcons * chore: update icon last modified entry with Date.now() when created * chore: update `overrideManifestIcons` hint * chore: change `handleHotUpdate` logic * chore: find existing links in html injection * chore: add pwa assets in vue router examples via env var * chore: update lockfile * chore: fix lint * chore: move pwa assets generator to optional dependency * chore: add integration options * chore: add integration option to resolved options * chore: add public and output integration options * chore: update transform index html logic * chore: update ypes and docs
- Loading branch information
Showing
43 changed files
with
1,758 additions
and
188 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
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,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>PWA Assets Generator</title> | ||
<style> | ||
#app { | ||
text-align: center; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.ts"></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,24 @@ | ||
{ | ||
"name": "assets-generator", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview", | ||
"dev:png": "PNG=true vite", | ||
"build:png": "PNG=true vite build", | ||
"preview:png": "PNG=true vite preview" | ||
}, | ||
"devDependencies": { | ||
"rimraf": "^5.0.5", | ||
"sharp": "^0.32.6", | ||
"sharp-ico": "^0.1.5", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.10", | ||
"vite-plugin-pwa": "workspace:*", | ||
"@vite-pwa/assets-generator": "^0.2.4", | ||
"workbox-window": "^7.0.0" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
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,26 @@ | ||
import { | ||
createAppleSplashScreens, | ||
defineConfig, | ||
minimal2023Preset, | ||
} from '@vite-pwa/assets-generator/config' | ||
|
||
export default defineConfig({ | ||
headLinkOptions: { | ||
preset: '2023', | ||
}, | ||
preset: { | ||
...minimal2023Preset, | ||
appleSplashScreens: createAppleSplashScreens({ | ||
padding: 0.3, | ||
resizeOptions: { fit: 'contain', background: 'white' }, | ||
darkResizeOptions: { fit: 'contain', background: 'black' }, | ||
linkMediaOptions: { | ||
log: true, | ||
addMediaScreen: true, | ||
basePath: '/', | ||
xhtml: true, | ||
}, | ||
}, ['iPad Air 9.7"']), | ||
}, | ||
images: process.env.PNG ? 'public/source-test.png' : 'public/favicon.svg', | ||
}) |
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,17 @@ | ||
const date = __DATE__ | ||
|
||
const app = document.querySelector<HTMLDivElement>('#app')! | ||
|
||
app.innerHTML = ` | ||
<div> | ||
<img src="/favicon.svg" alt="PWA Logo" width="60" height="60"> | ||
<h1>PWA Assets Generator</h1> | ||
<br/> | ||
<p>${date}</p> | ||
<br/> | ||
</div> | ||
` | ||
|
||
window.addEventListener('load', () => { | ||
import('./pwa.ts') | ||
}) |
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,15 @@ | ||
import { pwaInfo } from 'virtual:pwa-info' | ||
import { pwaAssetsHead } from 'virtual:pwa-assets/head' | ||
import { pwaAssetsIcons } from 'virtual:pwa-assets/icons' | ||
import { registerSW } from 'virtual:pwa-register' | ||
|
||
console.log(pwaInfo) | ||
console.log(pwaAssetsHead) | ||
console.log(pwaAssetsIcons) | ||
|
||
registerSW({ | ||
immediate: true, | ||
onNeedRefresh() { | ||
console.log('onNeedRefresh 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,5 @@ | ||
/// <reference types="vite/client" /> | ||
/// <reference types="vite-plugin-pwa/vanillajs" /> | ||
/// <reference types="vite-plugin-pwa/info" /> | ||
|
||
declare const __DATE__: string |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"lib": ["ES2020", "DOM", "DOM.Iterable", "WebWorker"], | ||
"useDefineForClassFields": true, | ||
"module": "ESNext", | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"resolveJsonModule": true, | ||
"types": ["vite/client", "vite-plugin-pwa/vanillajs", "vite-plugin-pwa/info", "vite-plugin-pwa/pwa-assets"], | ||
"allowImportingTsExtensions": true, | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noEmit": true, | ||
"isolatedModules": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["src"] | ||
} |
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,42 @@ | ||
import { defineConfig } from 'vite' | ||
import { VitePWA } from 'vite-plugin-pwa' | ||
|
||
export default defineConfig({ | ||
logLevel: 'info', | ||
define: { | ||
__DATE__: `'${new Date().toISOString()}'`, | ||
}, | ||
build: { | ||
sourcemap: true, | ||
}, | ||
plugins: [ | ||
VitePWA({ | ||
mode: 'development', | ||
base: '/', | ||
/* buildBase: '/test-build-base/', */ | ||
strategies: 'generateSW', | ||
registerType: 'autoUpdate', | ||
includeAssets: ['favicon.svg'], | ||
manifest: { | ||
name: 'Vite PWA', | ||
short_name: 'Vite PWA', | ||
theme_color: '#ffffff', | ||
}, | ||
pwaAssets: { | ||
config: true, | ||
overrideManifestIcons: true, | ||
}, | ||
workbox: { | ||
globPatterns: ['**/*.{js,css,html,png,svg,ico}'], | ||
cleanupOutdatedCaches: true, | ||
clientsClaim: true, | ||
skipWaiting: true, | ||
}, | ||
devOptions: { | ||
enabled: true, | ||
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
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
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
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
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
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
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
Oops, something went wrong.