Skip to content

Commit

Permalink
feat!: add experimental PWA assets generation and injection (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Feb 17, 2024
1 parent 08a2996 commit 98186aa
Show file tree
Hide file tree
Showing 18 changed files with 1,019 additions and 178 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Zero-config PWA Plugin for VitePress
- 🐞 **Development Support**: debug your custom service worker logic as you develop your application
- 🛠️ **Versatile**: integration with meta frameworks: [îles](https://github.com/ElMassimo/iles), [SvelteKit](https://github.com/sveltejs/kit), [VitePress](https://github.com/vuejs/vitepress), [Astro](https://github.com/withastro/astro), and [Nuxt 3](https://github.com/nuxt/nuxt)
- 💥 **PWA Assets Generator**: generate all the PWA assets from a single command and a single source image
- 🚀 **PWA Assets Integration**: serving, generating and injecting PWA Assets on the fly in your application

## 📦 Install

Expand Down
65 changes: 65 additions & 0 deletions examples/pwa-simple-assets-generator/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { defineConfig } from 'vitepress'
import { withPwa } from '@vite-pwa/vitepress'

const base = '/' // '/vite-plugin-pwa/'

export default withPwa(defineConfig({
vite: {
logLevel: 'info',
define: {
__DATE__: `'${new Date().toISOString()}'`,
},
},
base,
lang: 'en-US',
title: 'VitePress PWA',
description: 'Vite Plugin PWA Integration example for VitePress',
head: [
['meta', {
name: 'keywords',
content: 'PWA, VitePress, workbox, Vite, vite-plugin',
}],
],
themeConfig: {
footer: {
message: 'Released under the MIT License.',
copyright: 'Copyright © 2022-PRESENT Anthony Fu',
},
nav: [
{ text: 'Home', link: '/' },
{ text: 'About', link: '/about', activeMatch: '/about' },
{
text: 'Packages',
items: [
{ text: 'Foo', link: '/packages/foo' },
{ text: 'Bar', link: '/packages/bar' },
],
},
],
},
pwa: {
mode: 'development',
registerType: 'autoUpdate',
injectRegister: 'script-defer',
includeAssets: ['favicon.svg'],
manifest: {
name: 'VitePress PWA',
short_name: 'VitePressPWA',
theme_color: '#ffffff',
},
pwaAssets: {
config: true,
},
workbox: {
globPatterns: ['**/*.{css,js,html,svg,png,ico,txt,woff2}'],
},
experimental: {
includeAllowlist: true,
},
devOptions: {
enabled: false,
suppressWarnings: true,
navigateFallback: '/',
},
},
}))
10 changes: 10 additions & 0 deletions examples/pwa-simple-assets-generator/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: About
---
<script setup>
const date = __DATE__
</script>

# About

<pre>Generated at: {{ date }}</pre>
12 changes: 12 additions & 0 deletions examples/pwa-simple-assets-generator/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: VitePress PWA
titleTemplate: Zero-config PWA Plugin for VitePress
---

<script setup>
const date = __DATE__
</script>

# VitePress PWA

<pre>Generated at: {{ date }}</pre>
17 changes: 17 additions & 0 deletions examples/pwa-simple-assets-generator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "pwa-simple",
"type": "module",
"version": "0.0.0",
"private": "true",
"scripts": {
"dev": "vitepress dev",
"build": "vitepress build",
"preview": "nr build && vitepress serve",
"https": "nr build && serve .vitepress/dist"
},
"devDependencies": {
"@vite-pwa/vitepress": "workspace:*",
"https-localhost": "^4.7.1",
"typescript": "^5.2.2"
}
}
11 changes: 11 additions & 0 deletions examples/pwa-simple-assets-generator/packages/[pkg].md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Package
---

<script setup>
const date = __DATE__
</script>

# Package `{{ $params.pkg }}`

<pre>Generated at: {{ date }}</pre>
8 changes: 8 additions & 0 deletions examples/pwa-simple-assets-generator/packages/[pkg].paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
paths() {
return [
{ params: { pkg: 'foo' } },
{ params: { pkg: 'bar' } },
]
},
}
Empty file.
130 changes: 130 additions & 0 deletions examples/pwa-simple-assets-generator/public/favicon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/pwa-simple-assets-generator/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
25 changes: 25 additions & 0 deletions examples/pwa-simple-assets-generator/pwa-assets.config.ts
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',
})
27 changes: 27 additions & 0 deletions examples/pwa-simple-assets-generator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"incremental": false,
"target": "ESNext",
"lib": ["DOM", "ESNext"],
"module": "esnext",
"moduleResolution": "node",
"baseUrl": ".",
"types": [
"vite/client",
"vitepress",
"@vite-pwa/vitepress"
],
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"skipLibCheck": true
},
"include": [
"./*.ts",
"./.vitepress/**/*.ts",
"./.vitepress/**/*.vue"
],
"exclude": ["dist", "node_modules"]
}
1 change: 1 addition & 0 deletions examples/pwa-simple-assets-generator/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare const __DATE__: string
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@vite-pwa/vitepress",
"type": "module",
"version": "0.3.1",
"packageManager": "pnpm@8.11.0",
"packageManager": "pnpm@8.15.3",
"description": "Zero-config PWA for VitePress",
"author": "antfu <anthonyfu117@hotmail.com>",
"license": "MIT",
Expand Down Expand Up @@ -42,7 +42,13 @@
"release": "bumpp && npm publish"
},
"peerDependencies": {
"vite-plugin-pwa": ">=0.17.2 <1"
"@vite-pwa/assets-generator": "^0.2.4",
"vite-plugin-pwa": ">=0.19.0 <1"
},
"peerDependenciesMeta": {
"@vite-pwa/assets-generator": {
"optional": true
}
},
"devDependencies": {
"@antfu/eslint-config": "^0.43.1",
Expand All @@ -52,11 +58,11 @@
"bumpp": "^9.2.0",
"eslint": "^8.54.0",
"https-localhost": "^4.7.1",
"typescript": "^5.2.2",
"typescript": "^5.3.3",
"unbuild": "^2.0.0",
"vite": "^5.0.0",
"vite-plugin-pwa": ">=0.17.2 <1",
"vitepress": "1.0.0-rc.28"
"vite-plugin-pwa": ">=0.19.0 <1",
"vitepress": "1.0.0-rc.42"
},
"pnpm": {
"peerDependencyRules": {
Expand Down

0 comments on commit 98186aa

Please sign in to comment.