Revert "Disable workbox when running in webpack dev server, not in dev mode"

This reverts commit 11e676ce

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2020-10-01 14:04:21 +01:00
parent daa755017e
commit 87c42934ea
2 changed files with 5 additions and 16 deletions

View File

@ -38,20 +38,13 @@ export default class WebPlatform extends VectorBasePlatform {
super(); super();
// load service worker if available on this platform // load service worker if available on this platform
if ('serviceWorker' in navigator) { // Service worker is disabled in development: https://github.com/GoogleChrome/workbox/issues/1790
// clean up old dummy sw.js if ('serviceWorker' in navigator && process.env.NODE_ENV === "production") {
navigator.serviceWorker.getRegistration('sw.js').then(reg => reg.unregister()); navigator.serviceWorker.register('service-worker.js');
// Service worker is disabled in webpack-dev-server: https://github.com/GoogleChrome/workbox/issues/1790
if (!process.env.WEBPACK_DEV_SERVER) {
navigator.serviceWorker.register('service-worker.js');
} else {
// we no longer run workbox when in webpack-dev-server, clean it up
navigator.serviceWorker.getRegistration('service-worker.js').then(reg => reg.unregister());
}
} }
} }
getHumanReadableName(): string { getHumanReadableName(): string {
return 'Web Platform'; // no translation required: only used for analytics return 'Web Platform'; // no translation required: only used for analytics
} }

View File

@ -1,5 +1,4 @@
const path = require('path'); const path = require('path');
const {EnvironmentPlugin} = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin'); const TerserPlugin = require('terser-webpack-plugin');
@ -33,8 +32,6 @@ module.exports = (env, argv) => {
const jsSdkSrcDir = path.resolve(require.resolve("matrix-js-sdk/package.json"), '..', 'src'); const jsSdkSrcDir = path.resolve(require.resolve("matrix-js-sdk/package.json"), '..', 'src');
const plugins = [ const plugins = [
new EnvironmentPlugin(["WEBPACK_DEV_SERVER"]), // pass this as it is used for conditionally loading workbox
// This exports our CSS using the splitChunks and loaders above. // This exports our CSS using the splitChunks and loaders above.
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
filename: 'bundles/[hash]/[name].css', filename: 'bundles/[hash]/[name].css',
@ -95,8 +92,7 @@ module.exports = (env, argv) => {
}), }),
]; ];
const isDevServer = process.env.WEBPACK_DEV_SERVER; if (argv.mode === "production") {
if (!isDevServer) {
plugins.push(new WorkboxPlugin.GenerateSW({ plugins.push(new WorkboxPlugin.GenerateSW({
maximumFileSizeToCacheInBytes: 22000000, maximumFileSizeToCacheInBytes: 22000000,
runtimeCaching: [{ runtimeCaching: [{