diff --git a/package-lock.json b/package-lock.json index 657c5947..9a413009 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18003,6 +18003,12 @@ "integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=", "dev": true }, + "prettier": { + "version": "1.19.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", + "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "dev": true + }, "pretty-error": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/pretty-error/-/pretty-error-2.1.2.tgz", @@ -20957,6 +20963,15 @@ "lodash": "^4.17.15" } }, + "webpack-retry-chunk-load-plugin": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/webpack-retry-chunk-load-plugin/-/webpack-retry-chunk-load-plugin-1.5.0.tgz", + "integrity": "sha512-mE3YBQX0Ho09uQpnrCVOuwtnMbu8Ydzx6rF0lETxQnZpAf9fz/KL1HxOFDsyhPG9dH0nmCsCEj0reWhY65NJUQ==", + "dev": true, + "requires": { + "prettier": "^1.19.1" + } + }, "webpack-sources": { "version": "1.4.3", "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.4.3.tgz", diff --git a/package.json b/package.json index 174a022a..0b344b8e 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "webpack": "^4.46.0", "webpack-cli": "^3.3.12", "webpack-merge": "^4.2.2", + "webpack-retry-chunk-load-plugin": "^1.5.0", "worker-loader": "^3.0.8" } } diff --git a/webpack.common.js b/webpack.common.js index 0178e343..2ae9e48e 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -4,6 +4,7 @@ const MediaQueryPlugin = require('media-query-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const postcssPresetEnv = require('postcss-preset-env'); const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin'); +const { RetryChunkLoadPlugin } = require('webpack-retry-chunk-load-plugin'); const fs = require('fs'); const allowedIPs = ['127.0.0.1']; @@ -143,7 +144,21 @@ module.exports = { new ServiceWorkerWebpackPlugin({ entry: path.join(__dirname, 'src/lib/mtproto/mtproto.service.ts'), filename: 'sw.js', - excludes: ['**/*'], + //excludes: ['**/*'], + includes: [ + '**/*.js', + '**/*.css', + '**/*.json', + '**/*.wasm', + '**/*.mp3', + '**/*.svg', + '**/*.tgs', + '**/*.ico', + '**/*.woff', + '**/*.woff2', + '**/*.ttf', + '**/*.webmanifest' + ], }), new HtmlWebpackPlugin({ @@ -183,5 +198,23 @@ module.exports = { 'only screen and (min-width: 721px)': 'desktop', } }), + + new RetryChunkLoadPlugin({ + // optional stringified function to get the cache busting query string appended to the script src + // if not set will default to appending the string `?cache-bust=true` + cacheBust: `function() { + return Date.now(); + }`, + // optional value to set the amount of time in milliseconds before trying to load the chunk again. Default is 0 + retryDelay: 3000, + // optional value to set the maximum number of retries to load the chunk. Default is 1 + maxRetries: 999999, + // optional list of chunks to which retry script should be injected + // if not set will add retry script to all chunks that have webpack script loading + //chunks: ['chunkName'], + // optional code to be executed in the browser context if after all retries chunk is not loaded. + // if not set - nothing will happen and error will be returned to the chunk loader. + //lastResortScript: "window.location.href='/500.html';", + }), ], };