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

cssurl-rev

v1.1.0

Published

Append md5 hash to the url in CSS files

Downloads

3

Readme

cssurl-rev

给 CSS 文件中的 url 加上 md5 时间戳

travis badge

安装

npm install --save cssurl-rev

使用方法

var Rev = require('cssurl-rev');

new Rev()
    .src('css/*.css')
    .dest('build/css')
    .run(function (err, files) {
        // done callback
    });

你还可以给 run 方法传入一个 repalcer 来处理时间戳:

var Rev = require('cssurl-rev');
var replacer = function (url, hash) {
    return url + '?' + hash;
};

new Rev()
    .src('css/*.css')
    .dest('build/css')
    .run({ replacer: replacer }, function (err, files) {
        // done callback
    });

Example

app.css

@import url(http://example.com/reset.css?20150811);
@import url(buttons.css);

body {
    background: url(images/hello.png?v=20150811);
}

JS

new Rev()
    .src('app.css')
    .dest('build/')
    .run();

Output:

build/app.css

@import url(http://example.com/reset.css?20150811=&v={md5});
@import url(buttons.css?v={md5});

body {
    background: url(images/hello.png?v={md5});
}

之后会在 build 目录下生成处理过后的文件。里面所有的 url 都会加上一个其对应文件的 md5 值 (截取前 10 位)。

API

src(globs)

样式文件的路径,格式参考 vinyl-fs

dest(folder)

处理后的文件的保存的文件夹。可选

run([option, callback])

option

  • option.replacer:Function

    如果你自己处理 url 和 hash 的话可以设置一个 replacer

    function replacer(url, hash) {
        return url + '?' + hash;
    }
  • option.skipRemote

    跳过所有的远程的 url。即像 http://example.com/reset.css 这样的 url 会被忽略掉。默认是 false

callback(err, files)

处理完成或出错的回调函数