From fbdd888c3d8613039d674e1d9308d20c6c3c00b7 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 9 Jan 2020 22:40:10 +0200 Subject: [PATCH] Disable SW caching in dev build --- client/service-worker.js | 5 ++++- webpack.config.js | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/client/service-worker.js b/client/service-worker.js index 153a2659..4596d5da 100644 --- a/client/service-worker.js +++ b/client/service-worker.js @@ -78,7 +78,10 @@ async function networkOrCache(event) { } if (response.ok) { - event.waitUntil(putInCache(event.request, response)); + if (cacheName !== "dev") { + event.waitUntil(putInCache(event.request, response)); + } + return response.clone(); } diff --git a/webpack.config.js b/webpack.config.js index cc7ffa46..aba4eab8 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,8 +7,9 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const VueLoaderPlugin = require("vue-loader/lib/plugin"); const Helper = require("./src/helper.js"); +const isProduction = process.env.NODE_ENV === "production"; const config = { - mode: process.env.NODE_ENV === "production" ? "production" : "development", + mode: isProduction ? "production" : "development", entry: { "js/bundle.js": [path.resolve(__dirname, "client/js/vue.js")], }, @@ -108,7 +109,9 @@ const config = { from: "./client/service-worker.js", to: "[name].[ext]", transform(content) { - return content.toString().replace("__HASH__", Helper.getVersionCacheBust()); + return content + .toString() + .replace("__HASH__", isProduction ? Helper.getVersionCacheBust() : "dev"); }, }, {