From 78ee02b7cf0a7f1e86250f49df14bb0433245681 Mon Sep 17 00:00:00 2001 From: nyscherm Date: Tue, 15 May 2018 14:40:20 -0700 Subject: [PATCH] Add PWA features Add service worker with Workbox to allow caching of static assets and index page Expand on site.webmanifest --- .babelrc.js | 2 +- .env.sample | 3 + package.json | 3 +- public/site.webmanifest | 8 +- src/components/Html.js | 2 + src/server.js | 4 +- src/service-worker.js | 23 ++++++ tools/webpack.config.js | 10 ++- yarn.lock | 157 +++++++++++++++++++++++++++++++++++++++- 9 files changed, 201 insertions(+), 11 deletions(-) create mode 100644 src/service-worker.js diff --git a/.babelrc.js b/.babelrc.js index 92e416027..8dad6ed0a 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -22,7 +22,7 @@ module.exports = { }, }, ], - '@babel/preset-stage-2', + ["@babel/preset-stage-2", { "decoratorsLegacy": true }], '@babel/preset-flow', '@babel/preset-react', ], diff --git a/.env.sample b/.env.sample index 324ffe812..2d528adad 100644 --- a/.env.sample +++ b/.env.sample @@ -31,3 +31,6 @@ HONEYBADGER_API_KEY= # SendGrid info for email notifications SENDGRID_API_KEY= + +# Set as true to run https locally, add self-signed certificate in cert folder to trusted certificates +USE_HTTPS= diff --git a/package.json b/package.json index e941b0eb2..1f8e5e27b 100644 --- a/package.json +++ b/package.json @@ -188,7 +188,8 @@ "webpack-bundle-analyzer": "^2.11.1", "webpack-dev-middleware": "^3.1.2", "webpack-hot-middleware": "^2.21.2", - "webpack-node-externals": "^1.7.2" + "webpack-node-externals": "^1.7.2", + "workbox-webpack-plugin": "^3.2.0" }, "lint-staged": { "*.{js,jsx}": ["eslint --no-ignore --fix", "git add --force"], diff --git a/public/site.webmanifest b/public/site.webmanifest index 3992b48d7..4b8c7661e 100644 --- a/public/site.webmanifest +++ b/public/site.webmanifest @@ -1,4 +1,7 @@ { + "short_name": "Lunch", + "name": "Lunch", + "description": "An app for groups to decide on nearby lunch options.", "icons": [ { "src": "icon.png", @@ -6,5 +9,8 @@ "type": "image/png" } ], - "start_url": "/" + "start_url": "/", + "display": "standalone", + "theme_color": "#FFC0CB", + "background_color": "#FFF" } diff --git a/src/components/Html.js b/src/components/Html.js index 3a51e3257..5a922484a 100644 --- a/src/components/Html.js +++ b/src/components/Html.js @@ -74,6 +74,7 @@ class Html extends Component { + {scripts.map(script => ( @@ -92,6 +93,7 @@ class Html extends Component {