-
-
Notifications
You must be signed in to change notification settings - Fork 8
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 (#37)
- Loading branch information
Showing
20 changed files
with
522 additions
and
183 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,40 @@ | ||
import { defineConfig } from 'astro/config' | ||
import AstroPWA from '@vite-pwa/astro' | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
vite: { | ||
logLevel: 'info', | ||
define: { | ||
__DATE__: `'${new Date().toISOString()}'`, | ||
}, | ||
}, | ||
integrations: [ | ||
AstroPWA({ | ||
mode: 'development', | ||
base: '/', | ||
scope: '/', | ||
includeAssets: ['favicon.svg'], | ||
registerType: 'autoUpdate', | ||
manifest: { | ||
name: 'Astro PWA', | ||
short_name: 'Astro PWA', | ||
theme_color: '#ffffff', | ||
}, | ||
pwaAssets: { | ||
config: true, | ||
}, | ||
workbox: { | ||
navigateFallback: '/', | ||
globPatterns: ['**/*.{css,js,html,svg,png,ico,txt}'], | ||
}, | ||
devOptions: { | ||
enabled: false, | ||
navigateFallbackAllowlist: [/^\//], | ||
}, | ||
experimental: { | ||
directoryAndTrailingSlashHandler: true, | ||
} | ||
}), | ||
], | ||
}) |
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,18 @@ | ||
{ | ||
"name": "pwa-simple-assets-generator", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "astro dev", | ||
"start": "astro dev", | ||
"build": "astro build", | ||
"preview": "astro preview", | ||
"astro": "astro" | ||
}, | ||
"devDependencies": { | ||
"@vite-pwa/astro": "workspace:*", | ||
"astro": "^4.0.1", | ||
"workbox-window": "^7.0.0" | ||
} | ||
} |
Empty file.
130 changes: 130 additions & 0 deletions
130
examples/pwa-simple-assets-generator/public/favicon.svg
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,3 @@ | ||
# https://www.robotstxt.org/robotstxt.html | ||
User-agent: * | ||
Disallow: |
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,25 @@ | ||
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, | ||
xhtml: true, | ||
}, | ||
}, ['iPad Air 9.7"']), | ||
}, | ||
images: '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,3 @@ | ||
/// <reference types="astro/client" /> | ||
/// <reference types="vite-plugin-pwa/info" /> | ||
/// <reference types="vite-plugin-pwa/vanillajs" /> |
43 changes: 43 additions & 0 deletions
43
examples/pwa-simple-assets-generator/src/layouts/DefaultLayout.astro
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,43 @@ | ||
--- | ||
import { pwaInfo } from 'virtual:pwa-info'; | ||
import { pwaAssetsHead } from 'virtual:pwa-assets/head'; | ||
export interface Props { | ||
title: string; | ||
} | ||
// replaced dynamically | ||
const buildDate = __DATE__; | ||
const { title } = Astro.props as Props; | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>{title}</title> | ||
<meta name="description" content={title}> | ||
{ pwaAssetsHead.themeColor && <meta name="theme-color" content={pwaAssetsHead.themeColor.content} /> } | ||
{ pwaAssetsHead.links.map(link => ( | ||
<link {...link} /> | ||
)) } | ||
{ pwaInfo && <Fragment set:html={pwaInfo.webManifest.linkTag} /> } | ||
<script src="/src/pwa.ts"></script> | ||
<style> | ||
main, footer { | ||
text-align: center; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<main> | ||
<article> | ||
<slot /> | ||
</article> | ||
</main> | ||
<footer> | ||
Built at: { buildDate } | ||
</footer> | ||
</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,8 @@ | ||
--- | ||
import DefaultLayout from '../layouts/DefaultLayout.astro'; | ||
--- | ||
<DefaultLayout title="Astro PWA"> | ||
<h1>Page not found</h1> | ||
<h1>Upps, something is wrong, the requested page not found!</h1> | ||
<a href="/">Back home</a> | ||
</DefaultLayout> |
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,7 @@ | ||
--- | ||
import DefaultLayout from '../layouts/DefaultLayout.astro'; | ||
--- | ||
<DefaultLayout title="About - Astro PWA"> | ||
<h1>About - <a href="https://astro.build/">Astro</a> PWA!</h1> | ||
<a href="/">Go Home</a> | ||
</DefaultLayout> |
13 changes: 13 additions & 0 deletions
13
examples/pwa-simple-assets-generator/src/pages/index.astro
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,13 @@ | ||
--- | ||
import DefaultLayout from '../layouts/DefaultLayout.astro'; | ||
--- | ||
<DefaultLayout title="Astro PWA"> | ||
<h1>Welcome to <a href="https://astro.build/">Astro</a> PWA</h1> | ||
<a href="/about">Go /about</a> | ||
<br/> | ||
<a href="/about/">Go /about/</a> | ||
<br/> | ||
<a href="/test">Go to /test</a> | ||
<br/> | ||
<a href="/test/">Go to /test/</a> | ||
</DefaultLayout> |
9 changes: 9 additions & 0 deletions
9
examples/pwa-simple-assets-generator/src/pages/test/about.astro
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,9 @@ | ||
--- | ||
import DefaultLayout from '../../layouts/DefaultLayout.astro'; | ||
--- | ||
<DefaultLayout title="About Test Astro PWA"> | ||
<h1>Welcome to <a href="https://astro.build/">Astro</a> PWA</h1> | ||
<a href="/test">Go /test</a> | ||
<br/> | ||
<a href="/test/">Go /test/</a> | ||
</DefaultLayout> |
11 changes: 11 additions & 0 deletions
11
examples/pwa-simple-assets-generator/src/pages/test/index.astro
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,11 @@ | ||
--- | ||
import DefaultLayout from '../../layouts/DefaultLayout.astro'; | ||
--- | ||
<DefaultLayout title="Test Astro PWA"> | ||
<h1>Welcome to <a href="https://astro.build/">Astro</a> PWA</h1> | ||
<a href="/test/about">Go to /test/about</a> | ||
<br/> | ||
<a href="/test/about/">Go to /test/about/</a> | ||
<br/> | ||
<a href="/">Go to /</a> | ||
</DefaultLayout> |
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,13 @@ | ||
import { registerSW } from 'virtual:pwa-register' | ||
|
||
registerSW({ | ||
immediate: true, | ||
onRegisteredSW(swScriptUrl) { | ||
// eslint-disable-next-line no-console | ||
console.log('SW registered: ', swScriptUrl) | ||
}, | ||
onOfflineReady() { | ||
// eslint-disable-next-line no-console | ||
console.log('PWA application ready to work offline') | ||
}, | ||
}) |
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 @@ | ||
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,10 @@ | ||
{ | ||
"extends": "astro/tsconfigs/strict", | ||
"compilerOptions": { | ||
"types": [ | ||
"astro/client", | ||
"vite-plugin-pwa/vanillajs", | ||
"vite-plugin-pwa/info" | ||
] | ||
} | ||
} |
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.