From 5be30aae887d829ab58c7249d6cbdda92e691089 Mon Sep 17 00:00:00 2001 From: Alejandro Garcia Anglada Date: Tue, 31 Dec 2019 15:15:06 +0000 Subject: [PATCH] Support static export and server hosted build and update docs (#9783) --- examples/with-next-offline/README.md | 42 +++++++++++++++++++---- examples/with-next-offline/next.config.js | 4 ++- examples/with-next-offline/package.json | 8 +++-- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/examples/with-next-offline/README.md b/examples/with-next-offline/README.md index 680e93630a..087a1d0d7f 100644 --- a/examples/with-next-offline/README.md +++ b/examples/with-next-offline/README.md @@ -12,7 +12,7 @@ npx create-next-app --example with-next-offline with-next-offline-app yarn create next-app --example with-next-offline with-next-offline-app ``` -### Download manually +### Download Download the example: @@ -21,20 +21,48 @@ curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 cd with-next-offline ``` -Install it and run: +### Install dependecies ```bash npm install -npm run dev -npm run export -serve -s out # or yarn -yarn dev +``` + +### Build + +#### Static export + +```bash +npm run export +# or yarn export -serve -s out ``` +To serve it yourself, you can run: + +```bash +npx serve -s out +``` + +#### Server hosted + +```bash +npm run build +# or +yarn build +``` + +To serve it yourself, run: + +```bash +npm start +# or +yarn start +``` + +### Deploy + Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) ```bash diff --git a/examples/with-next-offline/next.config.js b/examples/with-next-offline/next.config.js index 6ff7f7cb5c..14d9c10d8f 100644 --- a/examples/with-next-offline/next.config.js +++ b/examples/with-next-offline/next.config.js @@ -2,7 +2,9 @@ const withOffline = require('next-offline') module.exports = withOffline({ workboxOpts: { - swDest: 'static/service-worker.js', + swDest: process.env.NEXT_EXPORT + ? 'service-worker.js' + : 'static/service-worker.js', }, experimental: { async rewrites() { diff --git a/examples/with-next-offline/package.json b/examples/with-next-offline/package.json index f9737d52bf..04ed33543b 100644 --- a/examples/with-next-offline/package.json +++ b/examples/with-next-offline/package.json @@ -6,13 +6,15 @@ "dev": "next", "build": "next build", "start": "next start", - "export": "next build && next export" + "export": "cross-env NEXT_EXPORT=true next build && cross-env NEXT_EXPORT=true next export" }, "dependencies": { "next": "canary", "next-offline": "4.0.6", "react": "16.12.0", - "react-dom": "16.12.0", - "serve": "11.2.0" + "react-dom": "16.12.0" + }, + "devDependencies": { + "cross-env": "6.0.3" } } -- GitLab