Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next offline #9010

Merged
merged 3 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions examples/with-next-offline/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# next-offline example

## How to use

### Using `create-next-app`

Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example:

```bash
npx create-next-app --example with-next-offline with-next-offline-app
# or
yarn create next-app --example with-next-offline with-next-offline-app
```

### Download manually

Download the example:

```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-next-offline
cd with-next-offline
```

Install it and run:

```bash
npm install
npm run dev
npm run export
serve -s out
# or
yarn
yarn dev
yarn export
serve -s out
```

Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))

```bash
now
```

## The idea behind the example

This example demonstrates how to use the [next-offline plugin](https://github.com/hanford/next-offline) It includes manifest.json to install app via chrome
5 changes: 5 additions & 0 deletions examples/with-next-offline/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const withOffline = require('next-offline')

const nextConfig = {}

module.exports = withOffline(nextConfig)
18 changes: 18 additions & 0 deletions examples/with-next-offline/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "with-next-offline",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"export": "next build && next export"
},
"dependencies": {
"next": "latest",
"next-offline": "4.0.6",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"serve": "11.2.0"
}
}
24 changes: 24 additions & 0 deletions examples/with-next-offline/pages/_document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Document, { Html, Head, Main, NextScript } from 'next/document'

class MyDocument extends Document {
static async getInitialProps (ctx) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps }
}

render () {
return (
<Html>
<Head>
<link rel='manifest' href='/manifest.json' />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}

export default MyDocument
1 change: 1 addition & 0 deletions examples/with-next-offline/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => <div>Next-Offline Example, try to install app via chrome</div>
16 changes: 16 additions & 0 deletions examples/with-next-offline/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "next-offline",
"short_name": "next-offline",
"description": "Nextjs using serveice worker via next-offline",
"icons": [
{
"src": "/static/pwa.png",
"sizes": "192x192",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"start_url": "/",
"display": "standalone"
}
Binary file added examples/with-next-offline/public/static/pwa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.