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

conveyor-belt

v1.0.0

Published

Pure asset management for Node, using globs and compatible with Gulp.

Downloads

18

Readme

conveyor-belt Build Status Coverage Status npm version

Pure asset management for Node/Express, using globs and compatible with Gulp.

Juggling different sets of assets for production, development, staging, etc? ConveyorBelt is a tiny Node.js module for loading different groups of front-end assets, depending on current environment. It uses globs so it plays nicely with Gulp, and you can use it with any build tool or Node framework.

It's time to get rid of those if (NODE_ENV === ...) statements!

Usage

npm install conveyor-belt --save
// Get an instance by supplying a number of environment configurations and current environment.
// Current environment must match one of the supplied environment configurations.
var conveyorBelt = require("conveyor-belt")({
    development: {
        scripts: [
            "bower/angular/angular.js"
            "assets/js/**/*.js",
            "!excluded.js"
        ],
        styles: [
            "bower/normalize-css/normalize.css",
            "assets/css/**/*.css",
        ]
    },
    production: {
        scripts: [
            "public/app.min-*.js"
        ],
        styles: [
            "public/app.min-*.css"
        ]
    }
}, process.env.NODE_ENV)

// Set assets to be accessible to the view. If you're using Express:
var app = require("express")()

app.use(function(req, res, next) {
    res.locals.assets = conveyorBelt.assets
    next()
})

// Or if you want a one-liner, attach it as an Express middleware.
// app.use(conveyorBelt.middleware.bind(conveyorBelt))

// Job done.
// Assets defined above will be available in
// a local variable called "assets" in the view, so just
// make sure you set the right NODE_ENV before running the app.

Optional - separate environment configs into a separate module (e.g. config.js):

module.exports = {
    development: {
        scripts: [
            "bower/angular/angular.js"
            "assets/js/**/*.js",
            "!assets/js/excluded.js"
        ],
        styles: [
            "bower/normalize-css/normalize.css",
            "assets/csss/**/*.css",
        ]
    },
    production: {
        scripts: [
            "public/app.min-*.js"
        ],
        styles: [
            "public/app.min-*.css"
        ]
    }
}
var config = require("./config")
var conveyorBelt = require("conveyor-belt")(config, process.env.NODE_ENV)

It's entirely up to you how you name your environments (you don't have to call them "development" and "production") and you can have as many as you want (e.g. add "staging"). Same applies for the keys inside each environment ("scripts", "styles", etc), as long as the value is an array of strings (paths or globs). Here's the general format:

{
    environment1: {
        assetsGroup1: [
            "path/to/file.js"
            "or/wildcards/**/*.js",
            "!excluded.js"
        ],
        assetsGroup2: [
            // ...
        ],
        assetsGroupX: [
            // ...
        ]
    },
    environmentX: {
        assetsX: [],
        whatever: []
    }
}

So that's a perfectly valid config:

var conveyorBelt = require("conveyor-belt")({
    superman: {
        powers: [
            "path/to/powers/*.png"
        ]
    }
}, "superman")

Rendering

After attaching the middleware, you can access the assets variable in your templates (set on res.locals). It will contain the same keys in your environment config. Here's an example with Jade that assumes you've specified scripts and styles in your environment config:

doctype html
html
    head
        each style in assets.styles
            link(rel='stylesheet', href="/#{style}")

    body
        each script in assets.scripts
            script(src="/#{script}")

Or if you take the superman example before that:

doctype html
html
    body
        each thing in assets.powers
            img(src="/#{thing}")

If you have the same keys in all environment configs ("scripts", etc) then the same code will work in all environments.

Contributions

Pull requests are more than welcome. Please make your changes in your own branch, make sure the current tests are passing (run with gulp mocha) and update/add tests if necessary. Run gulp to get your ES6 code transpiled to ES5.

Contributors