basic pwa setup

This commit is contained in:
Felix Roos 2023-02-06 20:57:34 +01:00
parent 10580a0bec
commit fd09dff381
16 changed files with 1678 additions and 72 deletions

2
.gitignore vendored
View File

@ -38,3 +38,5 @@ talk/public/samples
server/samples/old server/samples/old
repl/stats.html repl/stats.html
coverage coverage
public/icons/apple-splash-*
dev-dist

1653
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,13 @@ npm run build # <- builds repl + tutorial to ../docs
npm run preview # <- test static build npm run preview # <- test static build
``` ```
## Generate PWA icons
```sh
cd website/public
npx pwa-asset-generator icon.png icons
```
# Standard Readme of Astro Starter Kit: Docs Site # Standard Readme of Astro Starter Kit: Docs Site
```bash ```bash

View File

@ -9,6 +9,7 @@ import rehypeSlug from 'rehype-slug';
import rehypeAutolinkHeadings from 'rehype-autolink-headings'; import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import tailwind from '@astrojs/tailwind'; import tailwind from '@astrojs/tailwind';
import AstroPWA from '@vite-pwa/astro';
// import { visualizer } from 'rollup-plugin-visualizer'; // import { visualizer } from 'rollup-plugin-visualizer';
const options = { const options = {
@ -29,6 +30,45 @@ export default defineConfig({
react(), react(),
mdx(options), mdx(options),
tailwind(), tailwind(),
AstroPWA({
devOptions: {
enabled: true,
},
manifest: {
includeAssets: ['favicon.ico', 'icons/apple-icon-180.png', 'favicon.svg'],
name: 'Strudel REPL',
short_name: 'Strudel',
description:
'Strudel is a music live coding environment for the browser, porting the TidalCycles pattern language to JavaScript.',
theme_color: '#222222',
icons: [
{
src: 'icons/manifest-icon-192.maskable.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any',
},
{
src: 'icons/manifest-icon-192.maskable.png',
sizes: '192x192',
type: 'image/png',
purpose: 'maskable',
},
{
src: 'icons/manifest-icon-512.maskable.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any',
},
{
src: 'icons/manifest-icon-512.maskable.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable',
},
],
},
}),
], ],
site: `https://strudel.tidalcycles.org`, site: `https://strudel.tidalcycles.org`,
base: '/', base: '/',

View File

@ -39,6 +39,7 @@
"@types/react": "^18.0.26", "@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9", "@types/react-dom": "^18.0.9",
"astro": "^1.7.2", "astro": "^1.7.2",
"canvas": "^2.11.0",
"fraction.js": "^4.2.0", "fraction.js": "^4.2.0",
"nanoid": "^4.0.0", "nanoid": "^4.0.0",
"preact": "^10.7.3", "preact": "^10.7.3",
@ -47,10 +48,12 @@
"rehype-autolink-headings": "^6.1.1", "rehype-autolink-headings": "^6.1.1",
"rehype-slug": "^5.0.1", "rehype-slug": "^5.0.1",
"remark-toc": "^8.0.1", "remark-toc": "^8.0.1",
"tailwindcss": "^3.2.4", "tailwindcss": "^3.2.4"
"canvas": "^2.11.0"
}, },
"devDependencies": { "devDependencies": {
"html-escaper": "^3.0.3" "@vite-pwa/astro": "^0.0.1",
"html-escaper": "^3.0.3",
"vite-plugin-pwa": "^0.14.1",
"workbox-window": "^6.5.4"
} }
} }

BIN
website/public/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@ -1,4 +1,5 @@
--- ---
import { pwaInfo } from 'virtual:pwa-info';
import '../styles/index.css'; import '../styles/index.css';
const { BASE_URL } = import.meta.env; const { BASE_URL } = import.meta.env;
@ -12,7 +13,18 @@ const base = BASE_URL;
<link rel="icon" type="image/svg+xml" href="favicon.ico" /> <link rel="icon" type="image/svg+xml" href="favicon.ico" />
<meta
name="description"
content="Strudel is a music live coding environment for the browser, porting the TidalCycles pattern language to JavaScript."
/>
<link rel="icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/icons/apple-icon-180.png" sizes="180x180" />
<meta name="theme-color" content="#222222" />
<base href={base} /> <base href={base} />
<!-- Scrollable a11y code helper --> <!-- Scrollable a11y code helper -->
<script src="./make-scrollable-code-focusable.js" is:inline></script> <script src="./make-scrollable-code-focusable.js" is:inline></script>
<script src="/src/pwa.ts"></script>
{pwaInfo && <Fragment set:html={pwaInfo.webManifest.linkTag} />}

View File

@ -1 +1,3 @@
/// <reference types="astro/client" /> /// <reference types="astro/client" />
/// <reference types="vite-plugin-pwa/info" />
/// <reference types="vite-plugin-pwa/client" />

View File

@ -22,7 +22,7 @@ const currentFile = `src/pages${currentPage.replace(/\/$/, '')}.mdx`;
const githubEditUrl = `${CONFIG.GITHUB_EDIT_URL}/${currentFile}`; const githubEditUrl = `${CONFIG.GITHUB_EDIT_URL}/${currentFile}`;
--- ---
<html dir={frontmatter.dir ?? 'ltr'} lang={frontmatter.lang ?? 'en-us'} class="initial"> <html dir={frontmatter.dir ?? 'ltr'} lang={frontmatter.lang ?? 'en'} class="initial">
<head> <head>
<HeadCommon /> <HeadCommon />
<HeadSEO frontmatter={frontmatter} canonicalUrl={canonicalURL} /> <HeadSEO frontmatter={frontmatter} canonicalUrl={canonicalURL} />

View File

@ -3,7 +3,7 @@ import HeadCommon from '../components/HeadCommon.astro';
import { Repl } from '../repl/Repl.jsx'; import { Repl } from '../repl/Repl.jsx';
--- ---
<html> <html lang="en">
<head> <head>
<HeadCommon /> <HeadCommon />
<title>Strudel REPL</title> <title>Strudel REPL</title>

11
website/src/pwa.ts Normal file
View File

@ -0,0 +1,11 @@
import { registerSW } from 'virtual:pwa-register'
registerSW({
immediate: true,
onRegisteredSW(swScriptUrl) {
// console.log('SW registered: ', swScriptUrl)
},
onOfflineReady() {
// console.log('PWA application ready to work offline')
},
})

View File

@ -76,7 +76,7 @@ export function Footer({ context }) {
<FooterTab name="reference" /> <FooterTab name="reference" />
</div> </div>
{activeFooter !== '' && ( {activeFooter !== '' && (
<button onClick={() => setActiveFooter('')} className="text-white"> <button onClick={() => setActiveFooter('')} className="text-white" aria-label="Close Panel">
<XMarkIcon className="w-5 h-5" /> <XMarkIcon className="w-5 h-5" />
</button> </button>
)} )}

View File

@ -3,6 +3,10 @@
"compilerOptions": { "compilerOptions": {
"jsx": "react-jsx", "jsx": "react-jsx",
"skipLibCheck": true, "skipLibCheck": true,
"jsxImportSource": "react" "jsxImportSource": "react",
"noImplicitAny": false,
"types": [
"vite-plugin-pwa/client"
]
} }
} }