Skip to content

Commit

Permalink
feat!: add experimental PWA assets generation and injection (#117)
Browse files Browse the repository at this point in the history
* feat!: add experimental PWA assets generation and injection

* chore: add `playground-assets` for pwa assets

* chore: update playground-assets

* chore: update pwa plugin version

* chore: include layout in assets playground
  • Loading branch information
userquin committed Mar 6, 2024
1 parent 94ed504 commit f635750
Show file tree
Hide file tree
Showing 35 changed files with 1,359 additions and 272 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 Nuxt 3
- 🐞 **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
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@vite-pwa/nuxt",
"type": "module",
"version": "0.5.0",
"packageManager": "pnpm@8.15.1",
"packageManager": "pnpm@8.15.3",
"description": "Zero-config PWA for Nuxt 3",
"author": "antfu <anthonyfu117@hotmail.com>",
"license": "MIT",
Expand Down Expand Up @@ -60,7 +60,7 @@
"@nuxt/kit": "^3.9.0",
"pathe": "^1.1.1",
"ufo": "^1.3.2",
"vite-plugin-pwa": ">=0.18.1 <1"
"vite-plugin-pwa": ">=0.19.2 <1"
},
"devDependencies": {
"@antfu/eslint-config": "^0.43.1",
Expand All @@ -84,6 +84,14 @@
"resolutions": {
"@nuxt/kit": "^3.10.1"
},
"peerDependencies": {
"@vite-pwa/assets-generator": "^0.2.4"
},
"peerDependenciesMeta": {
"@vite-pwa/assets-generator": {
"optional": true
}
},
"build": {
"externals": [
"node:child_process",
Expand Down
6 changes: 6 additions & 0 deletions playground-assets/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<NuxtLoadingIndicator />
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</template>
6 changes: 6 additions & 0 deletions playground-assets/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div>
<NuxtPwaAssets />
<slot />
</div>
</template>
61 changes: 61 additions & 0 deletions playground-assets/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import process from 'node:process'

const sw = process.env.SW === 'true'

export default defineNuxtConfig({
/* ssr: false, */
// typescript,
modules: ['@vite-pwa/nuxt'],
future: {
typescriptBundlerResolution: true,
},
experimental: {
payloadExtraction: true,
watcher: 'parcel',
},
nitro: {
esbuild: {
options: {
target: 'esnext',
},
},
prerender: {
routes: ['/', '/about'],
},
},
imports: {
autoImport: true,
},
appConfig: {
// you don't need to include this: only for testing purposes
buildDate: new Date().toISOString(),
},
vite: {
logLevel: 'info',
},
pwa: {
mode: 'development',
strategies: 'generateSW',
registerType: 'autoUpdate',
manifest: {
name: 'Nuxt Vite PWA',
short_name: 'NuxtVitePWA',
theme_color: '#ffffff',
},
pwaAssets: {
config: true,
},
workbox: {
globPatterns: ['**/*.{js,css,html,png,svg,ico}'],
},
client: {
installPrompt: true,
},
devOptions: {
enabled: true,
suppressWarnings: true,
navigateFallback: '/',
navigateFallbackAllowlist: [/^\/$/],
},
},
})
15 changes: 15 additions & 0 deletions playground-assets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "playground-assets",
"type": "module",
"private": true,
"scripts": {
"dev": "nuxi dev",
"build": "nuxi build",
"generate": "nuxi generate"
},
"devDependencies": {
"@vite-pwa/assets-generator": "^0.2.4",
"@vite-pwa/nuxt": "workspace:*",
"nuxt": "^3.10.1"
}
}
17 changes: 17 additions & 0 deletions playground-assets/pages/about.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script setup lang="ts">
</script>

<template>
<div>
<h1>Nuxt Vite PWA</h1>
<ClientOnly>
PWA Installed: {{ $pwa?.isPWAInstalled }}
</ClientOnly>
<br>
<NuxtLink to="/">
Home
</NuxtLink>
<br>
<PwaTransparentImage image="pwa-192x192.png" alt="PWA Icon" />
</div>
</template>
17 changes: 17 additions & 0 deletions playground-assets/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script setup lang="ts">
</script>

<template>
<div>
<h1>Nuxt Vite PWA</h1>
<ClientOnly>
PWA Installed: {{ $pwa?.isPWAInstalled }}
</ClientOnly>
<br>
<NuxtLink to="/about">
About
</NuxtLink>
<br>
<PwaTransparentImage image="pwa-64x64.png" alt="PWA Icon" />
</div>
</template>
21 changes: 21 additions & 0 deletions playground-assets/public/favicon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions playground-assets/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',
})
3 changes: 3 additions & 0 deletions playground-assets/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nuxt/tsconfig.json"
}
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "my-module-playground",
"name": "playground",
"type": "module",
"private": true,
"scripts": {
Expand Down

0 comments on commit f635750

Please sign in to comment.