Automattic / browserbuild

Write for node, compile for browser.
170 stars 16 forks source link

Multiple basepaths, separated by a comma. #19

Closed slaskis closed 12 years ago

slaskis commented 12 years ago

The reason I'd like to be able to do this is really just to be able to use node_modules/ and lib/ as my basepaths. Because this way I can keep my library nicely separated into module.

Here's an example using TJs emitter-component:

// lib/epic.js

var Emitter = require('emitter-component');

function Epic(){
  Emitter.call(this);
  this.rowdy = false;
}

Epic.prototype = new Emitter;

Epic.prototype.thing = function(){
  if( this.rowdy )
    this.emit('AAAAH!');
  else
    this.emit('aaaah');
}
// Makefile

LIBS = lib/epic.js /
           node_modules/emitter-component/index.js

all: epic.min.js
    @:

epic.js: $(LIBS)
    node_modules/.bin/browserbuild -b lib/,node_modules/ -m epic $(LIBS) > $@

epic.min.js: epic.js
    node_modules/.bin/uglifyjs < $< > $@ 

So now, instead of having to download the emitter-component/index.js and add it to the repo we simply do this:

> npm i emitter-component
> make

It's also backwards compatible, so no harm done!

I really enjoy browserbuild though, so neat and tidy. Thanks!

rauchg commented 12 years ago

This is really cool

slaskis commented 12 years ago

thanks :)