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

express-asset-manager

v1.0.2

Published

Simple asset manager middleware for Express.js

Downloads

14

Readme

express-asset-manager

Simple and easy to integrate asset manager for Express.js applications

Installation

npm install express-asset-manager

Features :

  • Transparent asset management.
    • In development, each ressources are loaded by default.
    • In production, ressources are grouped and minified.
  • Group JavaScript and CSS files with node-minify
  • AMD support with require.js
  • Less support

| | Development | Production | | ----------------------- |:-------------:|:------------:| | JS (default) | Yes | Yes | | JS with AMD | Yes | Yes | | CSS (default) | Yes | Yes | | CSS with @import | Yes | Yes | | Less | Yes | Yes | | Less with @import | Yes | Yes | | CoffeeScript | Not yet | Not yet |

JS (default)

{
    "app.js" : {
        type: "js",
        dir: "js",
        files: [
            "../lib/jquery-1.9.1.js",
            "../lib/jquery.eventemitter.js",
            "../lib/knockout-2.2.1.js",
            "app.js",
            "models/User.js",
            "controllers/user.js",
        ]
    }
}

JS with AMD

{
    "app.js" : {
        type: "js",
        dir: "js",
        main: "app.js",
        lib: "../lib/require.js",
        mainConfigFile: "config.js", // optional, relative to `dir`
        includeLib: true // optional, default: false, include requirejs in the processed file 
    }
}

CSS (default)

{
    "style.css" : {
        type: "css",
        dir: "css",
        files: [
            "bootstrap.min.css",
            "bootstrap-responsive.min.css",
            "style.css",
            "style-responsive.css"
        ]
    }
}

CSS with @import

{
    "style.css" : {
        type: "css",
        dir: "css",
        main: "style.css"
    }
}

It uses requirejs to inline in production.

Less and Less with @import

{
    "style.css" : {
        type: "less",
        dir: "less",
        main: "style.less",
        lib: "../lib/less.js" // path to `less.js` to parse .less assets in the browser in dev env
    }
}

You need to write @import (inline) to inline CSS files in production.

Exemple of usage

var assets = {
    "app.js" : {
        type: "js",
        dir: "js",
        main: "app.js",
        lib: "../lib/require.js"
    },
    "style.css" : {
        type: "less",
        dir: "less",
        main: "style.less",
        lib: "../lib/less.js"
    }
};
var assetManagerConfig = {
    rootRoute   : "/static",
    srcDir      : "./public",
    buildDir    : "./builtAssets",
    process     : "true"
};
app.use(require("express-asset-manager")(assets, assetManagerConfig));

app.configure('development', function() {
    app.use(express.static('/static', './public'));
});

// in production, use a reverse proxy instead
app.configure('production', function() {
    app.use(express.static('/static', './builtAssets'));
});

In your views :

<!DOCTYPE html>
<html lang="en">
<head>
    <%- asset("style.css") %>
</head>
<body>
    <%-body -%>
    <%- asset("app.js") %>
</body>

Resulting page in development :

<!DOCTYPE html>
<html lang="en">
<head>
    <link href="/static/less/style.less" rel="stylesheet/less" type="text/css"/>
    <script src="/static/lib/less.js" type="text/javascript"></script>
</head>
<body>
    <%-body -%>
    <script src="/static/lib/require.js" data-main="/static/js/app" type="text/javascript"></script>
</body>

Resulting page in production :

<!DOCTYPE html>
<html lang="en">
<head>
    <link href="/static/less/style.css" type="text/css"/>
</head>
<body>
    <%-body -%>
    <script src="/static/lib/require.js" data-main="/static/js/app" type="text/javascript"></script>
</body>

At application startup, ./public/js/app.js will be read and processed by require.js optimizer. Output is saved in ./builtAssets/js/app.js.