From 117b4f021a8ff8923ac609fd532b64d3760bdfe6 Mon Sep 17 00:00:00 2001 From: Michael Fix Date: Thu, 14 Mar 2019 09:55:33 -0700 Subject: [PATCH] Add offline support (#699) * add offline support * update manifest to use desktop icon * simplify next-offline config * don't enable cache control on service workers --- next.config.js | 5 +++-- now.json | 15 ++++++++++++++- package.json | 2 +- static/manifest.json | 21 ++++++++++++--------- yarn.lock | 8 ++++---- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/next.config.js b/next.config.js index 121770d..13454ba 100644 --- a/next.config.js +++ b/next.config.js @@ -1,2 +1,3 @@ -// const { PHASE_DEVELOPMENT_SERVER } = require('next/constants') -// const withOffline = require('next-offline') +const withOffline = require('next-offline') + +module.exports = withOffline() diff --git a/now.json b/now.json index 7a86b86..e6fb27a 100644 --- a/now.json +++ b/now.json @@ -7,7 +7,20 @@ { "src": "^/about(.*)", "dest": "/about" }, { "src": "^/embed(.*)", "dest": "/embed" }, { "src": "^/_next/(.*)", "dest": "/_next/$1" }, - { "src": "^/static/(.*)", "dest": "/static/$1" }, + { + "src": "^/service-worker.js$", + "dest": "/_next/service-worker.js", + "headers": { + "Service-Worker-Allowed": "/" + } + }, + { + "src": "^/static/(.*)", + "dest": "/static/$1", + "headers": { + "cache-control": "public, max-age=43200, immutable" + } + }, { "src": "^/(.*)", "dest": "/index.html" } ], "build": { diff --git a/package.json b/package.json index c62274c..dd1e6c0 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "morphmorph": "^0.1.0", "ms": "^2.0.0", "next": "^8.0.3", - "next-offline": "^3.3.1", + "next-offline": "^3.3.6", "prettier": "^1.16.4", "react": "^16.8.3", "react-click-outside": "^3.0.0", diff --git a/static/manifest.json b/static/manifest.json index 8be5477..7eb81e0 100644 --- a/static/manifest.json +++ b/static/manifest.json @@ -6,13 +6,16 @@ "description": "Carbon is the easiest way to create and share beautiful images of your source code.", "display": "standalone", "start_url": "/", - "icons": [{ - "src": "/static/brand/icon.png", - "type": "image/png", - "sizes": "448x448" - }, { - "src": "/static/brand/logo-square.png", - "type": "image/png", - "sizes": "1024x1024" - }] + "icons": [ + { + "src": "/static/brand/icon.png", + "type": "image/png", + "sizes": "448x448" + }, + { + "src": "/static/brand/desktop.png", + "type": "image/png", + "sizes": "512x512" + } + ] } diff --git a/yarn.lock b/yarn.lock index ffd435f..30f28e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4839,10 +4839,10 @@ neo-async@^2.5.0: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.0.tgz#b9d15e4d71c6762908654b5183ed38b753340835" integrity sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA== -next-offline@^3.3.1: - version "3.3.5" - resolved "https://registry.yarnpkg.com/next-offline/-/next-offline-3.3.5.tgz#e4c3f33efb0c4f49f3e28abd513ccc3a8fc8080f" - integrity sha512-e6J838mppCpYMnbCvthoOSZNtAj9iFpJdVnCkuQTiIFU9IDP/GxKpjsixfP1UaTyHCmO2GzmyiYaglzFMPeVVQ== +next-offline@^3.3.6: + version "3.3.6" + resolved "https://registry.yarnpkg.com/next-offline/-/next-offline-3.3.6.tgz#3e35ad59d489c641a4d5745f5b06ce45faa53a42" + integrity sha512-hBlGTaWqv9xJf3c4WqjAfb6jO3+Rdfw42p9PQeQlsnO8G0bCg7GUxFebKDcK/b4scFFgmnvp4UNPt1vyMbpQgw== dependencies: clean-webpack-plugin "^0.1.19" copy-webpack-plugin "~4.5.2"