An open API service indexing awesome lists of open source software.

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

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