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

gulp-min-map

v0.1.0

Published

gulp plugin for CSS/JS minification mapping using HTML5 data attributes

Downloads

8

Readme

gulp-min-map

NPM version

gulp-min-map is a gulp plugin to create a file minification mapping of local js and css in your HTML files. It uses HTML5 data attributes to process the min files and will optionally rewrite the js and css links for you.

Usage

gulp-min-map is a plugin that provides a { minFile: [sourceFile1, sourceFile2, ..] } mapping/manifest object. You can pass this map object to a custom concatenation, minification, etc. gulp task.

Install as a dependency into project

npm install --save-dev gulp-min-map

Then use in your gulpfile.js (simple example)

var minFiles = {};

gulp.task("deploy-html", function() {
  return gulp.src("build/**/*.html")
    .pipe(plumber())
    .pipe(minMap(['js', 'css'], minFiles))
    .pipe(gulp.dest('release'));
});

gulp.task("deploy-js", function() {
  var streams = [];
  var jsMinFiles = minFiles.js;
  for (var minFile in jsMinFiles) {
    if (jsMinFiles.hasOwnProperty(minFile)) {
      var stream = gulp.src(jsMinFiles[minFile])
        .pipe(stripDebug())
        .pipe(uglify())
        .pipe(concat(minFile))
        .pipe(header(copyrightText, {}))
        .pipe(gulp.dest('release'));
      streams.push(stream);
    }
  }

  return es.merge.apply(es, streams);
});


gulp.task("deploy-css", function() {
  var streams = [];
  var cssMinFiles = minFiles.css;
  for (var minFile in cssMinFiles) {
    if (cssMinFiles.hasOwnProperty(minFile)) {
      var stream = gulp.src(cssMinFiles[minFile])
        .pipe(minifyCss())
        .pipe(concat(minFile))
        .pipe(header(copyrightText, {}))
        .pipe(gulp.dest('release'));
      streams.push(stream);
    }
  }

  return es.merge.apply(es, streams);
});

HTML

gulp-min-map will automatically detect local js and css references, and replace the src with the optional data-min attribute.

Example

Input:

<link rel="stylesheet" href="/css/bootstrap.css" data-min="bootstrap.min.css">
<link rel="stylesheet" href="/css/bootstrap-theme.css" data-min="bootstrap.min.css">
<link rel="stylesheet" href="/css/font-awesome.css" data-min="bootstrap.min.css">
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/css/home.css">
<link rel="stylesheet" href="/css/admin/admin.css">

Output:

<link rel="stylesheet" href="/css/bootstrap.min.css">
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/css/home.min.css">
<link rel="stylesheet" href="/css/admin/admin.min.css">

It will also build a mapping object that you can use for dependent gulp tasks

{
  "css": {
    "css/bootstrap.min.css":
      [ "/home/user/gulp-min-map/test/fixtures/css/bootstrap.css",
        "/home/user/gulp-min-map/test/fixtures/css/bootstrap-theme.css",
        "/home/user/gulp-min-map/test/fixtures/css/font-awesome.css" ],
     "css/home.min.css": [ "/home/user/gulp-min-map/test/fixtures/css/home.css" ],
     "css/admin/admin.min.css": [ "/home/user/gulp-min-map/test/fixtures/css/admin/admin.css" ]
  }
}

Options

minAttr

Type: string Default: "data-min"

The HTML element attribute that specifies the min file name to associate this element with.

noMinAttr

Type: string Default: "data-no-min"

The HTML element attribute that specifies that this element should be excluded from min file processing when automMin is true.

autoMin

Type: bool Default: true

Minimize files without a data-min attribute. Otherwise, leave as is.

defaultMinFile

Type: string Default: null

If autoMin is true, use this filename (e.g. 'app.min.js') for all elements without a data-min attribute. If defaultMinFile is null, the plugin will use the src file name instead (i.e. 'myfile.js' -> 'myfile.min.js').

updateHTML

Type: bool Default: true

Rewrite the input HTML files so the src uses the min files. Otherwise, the HTML file is left as is.

appendRev

Type: bool Default: false

If true, appends a query string '?rev=@@hash' to the end of the css or js file name when rewriting the HTML files. This format is compatible with the gulp-rev-append plugin for cache busting. Run gulp-rev-append on your HTML files after you have minified, concatenated, etc. your css and js files appropriately.

License

MIT License