npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

asset-cache-webpack-plugin

v1.1.1

Published

vue-webpack的离线缓存自定生成包

Downloads

5

Readme

asset-cache-webpack-plugin

离线缓存自动生成工具

注意:基本上只测试 vue-cli 上,其他有问题,可以提

[2020年9月24日] 介于chrome85+移除了离线缓存,添加pwa存储,功能一样。当chrome85+时,会启用pwa缓存。

安装

npm i asset-cache-webpack-plugin --save

特点

  • 完全自动化生成离线缓存文件 appcache
  • 资源加载由 html 文件转移到一个 js 文件加载,保证离线缓存更新及时
  • 极好的兼容性

使用

vue chain-webpack

const AssetCachePlugin = require("asset-cache-webpack-plugin")
// 启用离线缓存
// conf.plugin("app-cache").use(CachePlugin, [])
conf.plugin("asset-cache").use(AssetCachePlugin, [
    {
        // 离线缓存排除文件
        exclude: [/\.map$/],
        // 注解部分
        comment: "manifest",
        // 自定义 资源加载 可选参数
        assetLoader() {},
        // 循环assets时调用, 下面的例子是通过正则将页面中的外链资源地址找出并加入离线缓存清单文件中
        assetEach({ key, assets, cache }) {
            if (!/(?!\.html)\.(js|css)$/.test(key)) {
                // 匹配 css 和 js 排除 .html.js
                return
            }

            let source = assets[key].source()
            if (typeof source != "string") {
                return
            }

            source = source.match(/(?:(["'])|\()(?:(?:https?|ftp):)?[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|](?:\1|\))/g)
            if (!source) {
                return
            }
            source.forEach(function(url) {
                url = url.slice(1, url.length - 1)
                let sort = url.split(/[?#]/)[0]
                if (/\.(?:png|jpe?g|gif|svg|js|css|woff2?|eot|ttf|otf)$/.test(sort)) {
                    // 加入缓存列表,而且必须为这些结尾的外链资源
                    cache.addAsset(url)
                    return
                }
            })
        },
        // pwa cache 需要的版本号,不传会自动生成
        version: "v111",
        // 非清单文件中的文件,如果匹配,会自动离线
        // 不传,将不离线清单外的资源
        swAutoCacheReg: /\/\/file.democdn.cn\//,
        // serviceWork 开启状态 -1 关闭  0 自动(appCache没有的时候开启) 1 始终开启 注意:如果浏览器本身不支持,也无效
        swType: 1
    }
])

正常使用

// 全部使用默认值
new AssetCachePlugin()