1.0.0 • Published 5 years ago

staticfromcache v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

本地静态资源缓存化 介绍

  该插件主要适用于纯静态资源的本地化,或者是通过webpack打包后赖加载的模式,理论上支持vue react;已在vue中进行了实验
  插件支持两种缓存模式 localStorage 和indexedDB;可进行配置,如果配置了indexedDB,在发现浏览器不支持的情况下回降级到localStorage

插件使用

  插件本身依赖于webpack、html-webpack-plugin(index.html模板) 、min-css-extract-plugin(css提取),当然如果不单独提取css也没有关系
const LocalCache = require('localcache');
config.plugin('LocalCache').use(LocalCache, [{
      filename: 'css/[name].[contenthash:8].css',
      chunkFilename: 'css/[name].[contenthash:8].css',
      maxRetries: 3,
      type: 'localstorage',
      cacheIsOn: process.env.NODE_ENV === 'production',
      version: version,
      otherJs:''
      ...
    }])

插件配置使用说明

参数类型说明
filenamestring文件打包格式vue中默认为hash格式name.contenthash:8.
chunkFilename同上
maxRetriesnumber当不支持缓存的时候遇到js加载进行重试的次数
typestring支持localStorage、indexedDB,未进行配置的情况不走缓存逻辑
cacheSwitchboolean是否开启缓存模式
versionnumber版本号,主要是用于清空历史缓存的静态资源信息
jsOmitRegExp不需要处理的js
cssOmitREgExp不需要处理的css
otherJsOtherStaticContent额外在html中追加的js外链或者是code
otherCssOtherStaticContent额外在html中追加的css外链或者是code

OtherStaticContent

属性类型说明
innerHTMLstring需要插入的代码块
urlstring需要插入的外链