浏览代码

feat: added offline-plugin

NGPixel 7 年之前
父节点
当前提交
75d37cbdaf
共有 4 个文件被更改,包括 27 次插入3 次删除
  1. 1 0
      client/index.js
  2. 12 0
      dev/webpack/webpack.prod.js
  3. 1 0
      package.json
  4. 13 3
      yarn.lock

+ 1 - 0
client/index.js

@@ -2,4 +2,5 @@
 
 require('./scss/app.scss')
 require('./js/compatibility.js')
+require('offline-plugin/runtime').install()
 require('./js/app.js')

+ 12 - 0
dev/webpack/webpack.prod.js

@@ -4,6 +4,7 @@ const merge = require('webpack-merge')
 const CleanWebpackPlugin = require('clean-webpack-plugin')
 const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
 const ExtractTextPlugin = require('extract-text-webpack-plugin')
+const OfflinePlugin = require('offline-plugin')
 const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin')
 
 const common = require('./webpack.common.js')
@@ -21,6 +22,17 @@ module.exports = merge(common, {
       'process.env.NODE_ENV': JSON.stringify('production')
     }),
     new ExtractTextPlugin('css/bundle.css'),
+    new OfflinePlugin({
+      caches: {
+        main: [
+          'js/runtime.js',
+          'js/vendor.js',
+          'js/client.js'
+        ],
+        additional: [':externals:'],
+        optional: ['*.chunk.js']
+      }
+    }),
     new DuplicatePackageCheckerPlugin()
   ]
 })

+ 1 - 0
package.json

@@ -177,6 +177,7 @@
     "node-dev": "3.1.3",
     "node-sass": "4.7.2",
     "nodemon": "1.14.11",
+    "offline-plugin": "4.9.0",
     "postcss-loader": "2.0.10",
     "postcss-selector-parser": "3.1.1",
     "progress-bar-webpack-plugin": "1.10.0",

+ 13 - 3
yarn.lock

@@ -3022,7 +3022,7 @@ decompress-response@^3.2.0:
   dependencies:
     mimic-response "^1.0.0"
 
-deep-extend@~0.4.0, deep-extend@~0.4.1:
+deep-extend@^0.4.0, deep-extend@~0.4.0, deep-extend@~0.4.1:
   version "0.4.2"
   resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.2.tgz#48b699c27e334bf89f10892be432f6e4c7d34a7f"
 
@@ -3329,7 +3329,7 @@ ee-first@1.1.1:
   version "1.1.1"
   resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
 
-ejs@^2.5.6:
+ejs@^2.3.4, ejs@^2.5.6:
   version "2.5.7"
   resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.5.7.tgz#cc872c168880ae3c7189762fd5ffc00896c9518a"
 
@@ -6260,7 +6260,7 @@ loader-runner@^2.3.0:
   version "2.3.0"
   resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.3.0.tgz#f482aea82d543e07921700d5a46ef26fdac6b8a2"
 
-loader-utils@^0.2.15:
+loader-utils@0.2.x, loader-utils@^0.2.15:
   version "0.2.17"
   resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.17.tgz#f86e6374d43205a6e6c60e9196f17c0299bfb348"
   dependencies:
@@ -7408,6 +7408,16 @@ object.pick@^1.3.0:
   dependencies:
     isobject "^3.0.1"
 
+offline-plugin@4.9.0:
+  version "4.9.0"
+  resolved "https://registry.yarnpkg.com/offline-plugin/-/offline-plugin-4.9.0.tgz#0874960c0cb0c249f96b7cfc674217934660ed5c"
+  dependencies:
+    deep-extend "^0.4.0"
+    ejs "^2.3.4"
+    loader-utils "0.2.x"
+    minimatch "^3.0.3"
+    slash "^1.0.0"
+
 on-finished@^2.3.0, on-finished@~2.3.0:
   version "2.3.0"
   resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947"