瀏覽代碼

Переход на ServiceWorker вместо appcache

Book Pauk 5 年之前
父節點
當前提交
fba190c826
共有 4 個文件被更改,包括 18 次插入9 次删除
  1. 10 2
      build/webpack.prod.config.js
  2. 8 1
      client/index.html.template
  3. 0 5
      package-lock.json
  4. 0 1
      package.json

+ 10 - 2
build/webpack.prod.config.js

@@ -9,7 +9,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
 const CleanWebpackPlugin = require('clean-webpack-plugin');
 const CleanWebpackPlugin = require('clean-webpack-plugin');
 const HtmlWebpackPlugin = require('html-webpack-plugin');
 const HtmlWebpackPlugin = require('html-webpack-plugin');
 const CopyWebpackPlugin = require('copy-webpack-plugin');
 const CopyWebpackPlugin = require('copy-webpack-plugin');
-const AppCachePlugin = require('appcache-webpack-plugin');
+const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
 
 
 const publicDir = path.resolve(__dirname, '../dist/tmp/public');
 const publicDir = path.resolve(__dirname, '../dist/tmp/public');
 const clientDir = path.resolve(__dirname, '../client');
 const clientDir = path.resolve(__dirname, '../client');
@@ -55,6 +55,14 @@ module.exports = merge(baseWpConfig, {
             filename: `${publicDir}/index.html`
             filename: `${publicDir}/index.html`
         }),
         }),
         new CopyWebpackPlugin([{from: `${clientDir}/assets/*`, to: `${publicDir}/`, flatten: true}]),
         new CopyWebpackPlugin([{from: `${clientDir}/assets/*`, to: `${publicDir}/`, flatten: true}]),
-        new AppCachePlugin({exclude: ['../index.html']})
+        new SWPrecacheWebpackPlugin({
+            cacheId: 'liberama',
+            dontCacheBustUrlsMatching: /\.\w{8}\./,
+            filename: 'service-worker.js',
+            minify: true,
+            navigateFallback: '/index.html',
+            staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
+            stripPrefix: publicDir,
+        }),        
     ]
     ]
 });
 });

+ 8 - 1
client/index.html.template

@@ -1,11 +1,18 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
-<html manifest="/app/manifest.appcache">
+<html>
   <head>
   <head>
     <meta charset="utf-8">
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <meta name="description" content="Браузерная онлайн-читалка книг. Поддерживаются форматы: fb2, html, txt, rtf, doc, docx, pdf, epub, mobi.">
     <meta name="description" content="Браузерная онлайн-читалка книг. Поддерживаются форматы: fb2, html, txt, rtf, doc, docx, pdf, epub, mobi.">
     <meta name="keywords" content="онлайн,читалка,fb2,книги,читать,браузер,интернет">
     <meta name="keywords" content="онлайн,читалка,fb2,книги,читать,браузер,интернет">
     <title></title>
     <title></title>
+    <script>
+        (function() {
+            if('serviceWorker' in navigator) {
+                navigator.serviceWorker.register('/app/service-worker.js');
+            }
+        })();
+    </script>
   </head>
   </head>
   <body>
   <body>
     <div id="app"></div>
     <div id="app"></div>

+ 0 - 5
package-lock.json

@@ -937,11 +937,6 @@
         }
         }
       }
       }
     },
     },
-    "appcache-webpack-plugin": {
-      "version": "1.4.0",
-      "resolved": "https://registry.npmjs.org/appcache-webpack-plugin/-/appcache-webpack-plugin-1.4.0.tgz",
-      "integrity": "sha512-QA0D+3yJmpPk0CyfxYMOzhzV941rkTSjCnUEy2vS05GeqK+mMnBScQSB23lstvzYaFpkeWeLMO9RamtafhliYw=="
-    },
     "append-field": {
     "append-field": {
       "version": "1.0.0",
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",
       "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",

+ 0 - 1
package.json

@@ -56,7 +56,6 @@
   },
   },
   "dependencies": {
   "dependencies": {
     "@quasar/extras": "^1.5.2",
     "@quasar/extras": "^1.5.2",
-    "appcache-webpack-plugin": "^1.4.0",
     "axios": "^0.18.1",
     "axios": "^0.18.1",
     "base-x": "^3.0.8",
     "base-x": "^3.0.8",
     "chardet": "^0.7.0",
     "chardet": "^0.7.0",