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-usemin-reloaded

v0.2.1

Published

A better usemin.

Downloads

11

Readme

gulp-usemin-reloaded

A better usemin.

Why?

Once I've begun to develop using Gulp tasks and plugins, I've discovered that a lot of them are done in a really crappy way. The feature itself is cool but the code is unmanageable in the future. So, this is my effort to bring a better usemin with a cleaner logic and extensibility, but also proving a retrocompatibility layer with all existing usemin projects.

Features

  • Full UseMin compatible.
  • Extensible through callbacks (you do what you want with your own rules)
  • Extensible rules (why stick only with build:something when you can write myrule:context?)
  • Gulp Vinyl Stream compatible using gulp-through

How to install

npm install gulp-usemin-reloaded

Documentation

Rules

As you already know there are some standard rules that usemin tasks were using like build:css, build:js or build:remove. With this plugin we're going to extend those by using a more generic approach:

action:context outputPath [attributes]

where

  • action is the name of your own task (i.e. build)
  • context is the tag to recognize your task (i.e. css)
  • outputPath is where you want this to be saved, relative to your gulp.dest path (i.e. css/screen.css)
  • [attributes] are tha HTML attributes to append to the output tag that will be replaced (i.e. media="screen")

Callback

Usually usemin does everything out-of-the-box by itself, but since we're going to have custom Rules, we're also going to have custom callbacks to manage them. It's really simple to do that when you declare this plugin in your own gulpfile.js.

var usemin = require('gulp-usemin-reloaded');

.pipe(
    usemin({
        rules: {
            build: {
                css: [minifyCss(), 'concat'],
                js: [uglify(), rev()],
                html: [minifyHtml({empty: true})],
                remove: function( object, content ) {
                    return '';
                }
            }
        }
    })
)

In this case the remove task (aka context) is declared as a callback.

as INPUT parameters you have:

  • object is the parsed object of the current task rule (aka 'action`). It's a dictionary containing all the parsed HTML as a lookup dictionary.
  • content is the current evaluated content that can be manipulated directly from the callback.

as OUTPUT it expect the handled content, in this case an empty string (we want to discard everything that is between <!-- build:remove --> and <!-- endbuild -->. The replacement will be done ALWAYS by the plugin and not by you. So do NOT ever return the modified 'content' parameter. That is only a READ-ONLY var that you can use to base your decision (do 'if' or some other logical operators).

You can declare as many actions and contexts you like. Their value can be:

  • array of other tasks to be run
  • callback as described

Object

Of course the whole refactory is based on one logic. Every HTML tag is parsed as a dictionary and could be read and/or extend with different values. This is an example on how it will look like:

HTML

<!-- build:remove -->
<script src="js/null.js"></script>
<!-- endbuild -->

DICTIONARY

{
    action: 'build',
    context: 'remove',
    nodes: [
        {
            _tagName: 'script',
            src: 'js/null.js'
        }
    ],
    startTag: 'build: remove',
    endTag: 'endbuild',
    files: [
        // List of Vinyl INPUT Files ( src/href for each HTML tag )
    ]
}

License

See LICENSE file.