提交 ec40d51d 编写于 作者: A armspkt 提交者: Tim Neutkens

Next offline (#9010)

* example: add next-offline example

* fix: fix readme

* fix: lint standard
上级 c6609e5b
# 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
const withOffline = require('next-offline')
const nextConfig = {}
module.exports = withOffline(nextConfig)
{
"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"
}
}
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
export default () => <div>Next-Offline Example, try to install app via chrome</div>
{
"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"
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册