https://github.com/ragingwind/now-next-pwa
now builder for Next.js with PWA
https://github.com/ragingwind/now-next-pwa
Last synced: about 1 year ago
JSON representation
now builder for Next.js with PWA
- Host: GitHub
- URL: https://github.com/ragingwind/now-next-pwa
- Owner: ragingwind
- Created: 2019-08-26T23:02:25.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T09:00:23.000Z (over 3 years ago)
- Last Synced: 2025-04-09T04:24:45.960Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 1.36 MB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 31
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# now-next-pwa
> now builder for Next.js PWA. WARNING, This project is in experimental stage. APIs and others would be changed

# Getting Started
## Set up project and Install builder
```sh
now init nextjs
cd nextjs
```
## Add code for service worker registration to pages/index.js
```js
import React, { useEffect } from 'react';
function Home() {
...
useEffect(() => {
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/sw.js')
.then(registration => {
console.log('service worker registration successful');
})
.catch(err => {
console.warn('service worker registration failed', err.message);
});
}
}, []);
return (
...
);
}
```
## Add manifest to components/head.js and icon resources under `static`
```js
const Head = props => (
...
...
);
```
## Configure `now.json` with workbox and manifest custom setting as you need
```json
{
"version": 2,
"builds": [
{
"src": "package.json",
"use": "now-next-pwa",
"config": {
"workbox": {
"globPatterns": [],
"globIgnores": [],
"importScripts": [
"libs/sw-imports.js"
],
"offlineGoogleAnalytics": false
},
"manifest": {
"name": "NEXT-PWA-BASIC",
"short_name": "NEXT-PWA-BASIC",
"icons": [
{
"src": "/static/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/static/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
}
}
]
}
```
## Deploy to now
```sh
now
```
or you can test in development mode of now
```sh
now dev
```
# License
MIT @ Jimmy Moon