Skip to content


Subversion checkout URL

You can clone with
Download ZIP
asset management system for nodejs
JavaScript CSS
Branch: master
Failed to load latest commit information.
examples/hello-world remove csshost and htmlhost processors, because the same can be done …
lib remove strange feature
test remove strange feature
.gitignore closes #6, now doing base64 encoding only for jpg, png and gif images
Makefile added new processor which adds vendor specific prefixes to css
index.js remove static server
package.json remove strange feature #15, #16 fixed semicolon, now using different css minifier.


AMS - asset management system for nodejs. The goal is to have a flexible and powerful system for dependency management and preprocessing of static files.

What is ams?

  • very flexible build tool
  • dependency detector to combine files (using @import for css and require('module') for javascript)
  • easy extendable preprocessing framework
  • enables you to write your js code for the client in the same way as the nodejs server (commonjs modules)


  • Expressive API
  • Find your files
    • static dependencies detection (looks for commonjs 'require' calls)
    • finder using regexp
  • process
    • minify js (using uglifyjs)
    • minify css (using cssmin from yahoo)
    • wrap js with commonjs module definition string (requirejs compatible) for transport
    • add vendor css prefixes (-o, -ms, -moz, -webkit)
    • inline small images in css using base64 data encoding
    • combine css files using @import declaration
    • add host to background image paths and external css (@import), to load it from cdn
    • add your own preprocessor ...
  • combine
  • write to disk


npm install ams


require ams

var ams = require('ams');

Create a build instance from passed root path. Returns build Instance. Instance properties are:

  • this.root - passed path to the src dir.
  • this.options - current options object, contains all options for all methods.
  • this.paths - like require.paths.
  • - key/value hash of path/contents


var build ='/path/to/src');


Find files to be added to the build instance. Returns build Instance.

Defaults are:

    detect: null, // path to the file, where static 'require' dependencies tracking should start from,
    pattern: /\.[\w]+$/, // regexp to match files, is used if detect is not defined
    filter: null, // regexp to filter files, is used if detect is not defined
    rec: true, // recursive search, is used if detect is not defined
    paths: null // like require.paths to resolve deps



Build#add(path, [targetDir]);

Add file or files (array) from given path, optionally define the target dir. Returns build Instance.


// or
build.add(['/path/to/file1', '/path/to/file2']);


Run processors over files previously added to the build instance. Returns build Instance.

Defaults are:

    uglifyjs: true, // minify javascript using uglifyjs
    cssvendor: true, // add css vendor prefixes like -webkit, -moz etc.
    dataimage: true, // inline small images using data:image base64 encoded data for css and html
    cssimport: true, // parse @import declarations and inline css files
    cssabspath: true, // absolutize paths in css files (relative to the root)
    htmlabspath: true, // absolutize paths in html files (relative to the root)
    cssmin: true, // minify css using js port of yahoos compressor for css
    jstransport: true, // wrap javascript code in commonjs transport proposal, can be used with requirejs later
    texttransport: true // wrap any data into js transport string, f.e. to load html templates using requirejs from cdn

You can turn off any processor, add your own, or set any options for every processor.


    uglifyjs: false,
    cssabspath: {
        host: 'http://localhost:8888',
        verbose: true

If options is a function, it will be called for each file and act like a custom preprocessor.


build.process(function(path, data) {
    // `path` is path to the file
    // `data` is contents of the file
    // `this` is reference to build instance


Combine all files of current build instance to one, of course without mixing css and js etc. Returns build Instance.


    js: 'main.js',
    css: 'main.css'


Remove all files and dirs from given dir. Returns build Instance.




Write proccessed files to disk in passed dir. Returns build Instance.




Write a success message to stdout, pass a message string optionally. Returns build Instance.

Example of complete build script:

var ams = require('ams');

var publ = __dirname + '/public',
    src = __dirname + '/src',
    host = 'http://localhost:8888';
    // create a build for the dir
    // find all files in it
    // change processors options
        cssabspath: {
            host: host,
            verbose: true
        htmlabspath: {
            host: host,
            verbose: true
        texttransport: false,
        uglifyjs: {
            verbose: true
    // combine all js files
        js: 'main.js'
    // write them to disk
    // stdout success message
Something went wrong with that request. Please try again.