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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gulp-custom-css-urls

v0.3.0

Published

a gulp plugin custom image url inline in css

Downloads

48

Readme

gulp-custom-css-urls

Build Status via Travis CI Coverage Status

a plugin for gulp to custom you image url inline css file, and support output image file, then you can upload image file to Cloud CDN.

usage

var customCssUrls = require('gulp-custom-css-urls');
var gulp = require('gulp');
var path = require('path');
gulp.task('cssDemo',function(){
  return gulp.src('assets/**/*.css')
    .pipe(customCssUrls({
      /** 
       * static filepath relative absolute filepath's physical position. 
       * eg: 
       * image path inline css is '/images/demo.png', 
       * image absoulte filepath is '/Users/Navy/Desktop/code/demo/assets/images/demo.png', 
       * the process(process.cwd()) path is '/Users/Navy/Desktop/code/demo', 
       * so the image path relative website root path is 'assets/'
      */
      staticfile_relative_website_rootpath: 'assets/', 
      outputImage: true, // output images file , default to false
      outputImage_path: './.gulp_dist_output_images', // default to './.gulp_dist_output_images'
      modify: function (imageRelativePath, cssFilePath, imageRelativeWebsiteRootPath, imgInfo) {
        // modify image url before prepend or append
        // the imgInfo param is object, {hash: 3503865059, width: 1782, height: 530, orgin_filename: 'custom.png'}
        return path.join(imageRelativeWebsiteRootPath, path.basename(imageRelativePath)); //let the relative path become an absolute path
      },
      prepend: '', // prepend string before image url
      append: '', // append string after image url
      processPath: process.cwd() // custom process path , default to process.cwd()
    }))
    .pipe(gulp.dest('tmp/'));
});
gulp.task('jadeDemo',function() {
  return gulp.src('views/test.jade')
    .pipe(customCssUrls({
      staticfile_relative_website_rootpath: staticfile_relative_website_rootpath,
      modify: function (imageRelativePath, cssFilePath, imageRelativeWebsiteRootPath, imgInfo) {
        imageRelativePath.should.equal('example_1968_920.1373564769.png');
        imageRelativeWebsiteRootPath.should.equal('/images');
        imgInfo.should.have.properties({hash: 1373564769, width: 1968, height: 920, orgin_filename: 'example.png' });
        return path.join(imageRelativeWebsiteRootPath, imageRelativePath);
      },
      outputImage: true,
      ext: 'jade',
      outputImage_path: './.test_dist_img'
    }))
});

//rollback template content
gulp.task('returnToOrigin', function() {
  return gulp.src('views/forcemodify.html')
    .pipe(customCssUrls({
      forceModify: function (imageUrl, filePath) {
        var qiniu_host = 'https://demo.com';
        var ext = path.extname(imagesUrl);
        if (!ext) {
        return imagesUrl;
        }
        return imagesUrl.replace(ext, '').replace(qiniu_host, '').replace(/_\d{1,}_\d{1,}\.\d{1,}$/, '') + ext;
      },
      ext: 'html'
    }))
    .pipe(gulp.dest('views/'))
});
gulp.task('default',['cssDemo']);
gulp.task('jade',['jadeDemo']);
gulp.task('originTemplateContent',['returnToOrigin']);

//css file content, input:

div{background-image: url('/images/example.png');}

// output filename formats: (filename + '' + imgWidth + '' + imgHeight + '.' + crc32 + ext)

div{background-image: url('/images/example_width_height.hash.png');}

test

  • npm test
  • npm run cov

change log

  • 0.3.0

    feature support:
      image src support leftspace and rightspace.
  • 0.2.2

    bug fix:
      when template contain script, and have code xxx.src=xxx, will cause bug.
  • 0.2.0

    add option forceModify:
      which is a function , change url and direct return result.
  • 0.1.0

    add option ext:
      which support css, html ,jade, default css.
    add option skip:
      which is a array, url will skip when contain character in skip array.
  • 0.0.1

    only support css file.