1.0.0 • Published 5 years ago
staticfromcache v1.0.0
本地静态资源缓存化 介绍
该插件主要适用于纯静态资源的本地化,或者是通过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:''
...
}])
插件配置使用说明
参数 | 类型 | 说明 |
---|---|---|
filename | string | 文件打包格式vue中默认为hash格式name.contenthash:8. |
chunkFilename | 同上 | |
maxRetries | number | 当不支持缓存的时候遇到js加载进行重试的次数 |
type | string | 支持localStorage、indexedDB,未进行配置的情况不走缓存逻辑 |
cacheSwitch | boolean | 是否开启缓存模式 |
version | number | 版本号,主要是用于清空历史缓存的静态资源信息 |
jsOmit | RegExp | 不需要处理的js |
cssOmit | REgExp | 不需要处理的css |
otherJs | OtherStaticContent | 额外在html中追加的js外链或者是code |
otherCss | OtherStaticContent | 额外在html中追加的css外链或者是code |
OtherStaticContent
属性 | 类型 | 说明 |
---|---|---|
innerHTML | string | 需要插入的代码块 |
url | string | 需要插入的外链 |
1.0.0
5 years ago