From 903ad14bbc1cfbbf5e4757bb4d37329977a83556 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Thu, 25 Oct 2018 16:50:38 +0200 Subject: [PATCH] Add a service worker and cache assets Assets are served from the local cache preferably. They are fetched from the network if not available. This new addition also enables the "Add to homescreen" in Chrome/Chromium. Fix #22. --- .eslintrc.js | 1 + build/webpack.base.conf.js | 4 ++ package.json | 1 + src/App.vue | 9 +++ src/components/Map.vue | 3 +- src/components/ReportCard.vue | 3 +- src/components/ReportDialog/index.vue | 3 +- src/components/ReportsDescription.vue | 3 +- src/constants.js | 58 +--------------- src/report-types.js | 57 +++++++++++++++ src/sw.js | 99 +++++++++++++++++++++++++++ support/nginx/cyclassist.conf | 9 +++ yarn.lock | 6 ++ 13 files changed, 195 insertions(+), 61 deletions(-) create mode 100644 src/report-types.js create mode 100644 src/sw.js diff --git a/.eslintrc.js b/.eslintrc.js index c0128b6..1053bb4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -43,6 +43,7 @@ module.exports = { } ], 'no-bitwise': 'off', + 'no-unused-expressions': ["error", { "allowShortCircuit": true }], 'function-paren-newline': 'off', } } diff --git a/build/webpack.base.conf.js b/build/webpack.base.conf.js index c48c623..5fa1dc5 100644 --- a/build/webpack.base.conf.js +++ b/build/webpack.base.conf.js @@ -8,6 +8,7 @@ const CopyWebpackPlugin = require('copy-webpack-plugin') const HtmlWebpackPlugin = require('html-webpack-plugin') const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); +const ServiceWorkerWebpackPlugin = require("serviceworker-webpack-plugin"); const UglifyJsPlugin = require('uglifyjs-webpack-plugin') const VueLoaderPlugin = require('vue-loader/lib/plugin') @@ -189,6 +190,9 @@ module.exports = { child_process: 'empty', }, plugins: [ + new ServiceWorkerWebpackPlugin({ + entry: path.join(__dirname, '../src/sw.js'), + }), new VueLoaderPlugin(), new MiniCssExtractPlugin({ filename: utils.assetsPath('css/[name].[contenthash:4].css'), diff --git a/package.json b/package.json index 83cf8c6..119564f 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "nosleep.js": "^0.7.0", "ol": "^5.1.3", "roboto-fontface": "^0.9.0", + "serviceworker-webpack-plugin": "^1.0.1", "vue": "^2.5.2", "vue-i18n": "^8.0.0", "vue-router": "^3.0.1", diff --git a/src/App.vue b/src/App.vue index a621878..fdce398 100644 --- a/src/App.vue +++ b/src/App.vue @@ -63,6 +63,8 @@ diff --git a/src/components/Map.vue b/src/components/Map.vue index 99f32c3..0b8358f 100644 --- a/src/components/Map.vue +++ b/src/components/Map.vue @@ -46,6 +46,7 @@ import compassIcon from '@/assets/compass.svg'; import compassNorthIcon from '@/assets/compassNorth.svg'; import unknownMarkerIcon from '@/assets/unknownMarker.svg'; import * as constants from '@/constants'; +import REPORT_TYPES from '@/report-types'; import { distance } from '@/tools'; const MAIN_VECTOR_LAYER_NAME = 'MAIN'; @@ -177,7 +178,7 @@ export default { ? constants.LARGE_ICON_SCALE : constants.NORMAL_ICON_SCALE ), - src: constants.REPORT_TYPES[marker.type].marker, + src: REPORT_TYPES[marker.type].marker, }), })); // Add the marker to the map and keep a reference to it diff --git a/src/components/ReportCard.vue b/src/components/ReportCard.vue index a21b756..7cf4559 100644 --- a/src/components/ReportCard.vue +++ b/src/components/ReportCard.vue @@ -49,7 +49,8 @@