browserify_ruby

Browserify + Watchify wrapped in a ruby gem!

Installation

node

$ npm install -g browserify

$ npm install -g watchify

Add this line to your application's Gemfile:

ruby

$ gem 'browserify_ruby', group: :development

And then execute:

$ bundle

Or install it yourself as:

$ gem install browserify_ruby

Usage

You must have browserify and watchify installed globally for this to work.

For starters, after you've bundled the gem execute

$ bify init

This will create (from the root directory of your app)

  • .browserify_ruby.json (config file)
  • app/browserify (default source location)
  • app/assets/javascripts/bundles (default bundle location -- Rails happiness)

Open up the config file (.browserify_ruby.json)

.browserify_ruby.json

  • "source_directory"

    • The source directory of all your browserifying madness.
    • default: app/browserify
  • "bundle_directory"

    • The bundle destination after all of the browserifying/watchifying.
    • default: app/assets/javascripts/bundles
  • "manifest"

    • An array of objects containing 3 properties
      • "name":
        • source_alias_name,
      • "source":
        • entry point where you want to browserify. Searches from the source_directory
      • "bundle":
        • the bundle file name you want. Will output in bundle_directory

CLI

bify (i.e. browserify)

$ bify init: 
     => Creates a default scaffold. Run this first before executing
     => the other commands. See Usage above fore more details

$ bify start [NAMES]:
     => Runs browserify on all of the manifests indicated
     => in the manifest array of the .browserify_ruby.json file.
     => Takes optional list of names to browserify:
     => e.g. bify start name1 name2

$ bify watch [NAMES]:
     => Runs watchify on all of the manifests indicated
     => in the manifest array of the .browserify_ruby.json file.
     => Takes optional list of names to watchify:
     => e.g. bify watch name1 name2

$ bify clean:
     => Cleans out what ever bundles you have in the "bundle_directory"

$ bify list:
     => Lists all bundles in the "bundle_directory"

$ bify purge
     => Not a fan of browserify_ruby?
     => That's ok! This command will remove everything specified
     => in the .browserify_ruby.json file and removes the file too

FAQ

  1. Why wrap npm modules in a ruby gem?

    Because :) Well actually, I find it easier to write threads in ruby than in node. Once I figure that out, expect an npm module shortly after :)

  2. Is it necessary?

    Nope but trust me, you're in for a sweet ride.

  3. WHAT ABOUT TESTS?

    Uh...Not yet. To be honest, I'm not exactly sure how to implement tests with this kind of program Definitely open to suggestions though - and as always - pull requests.

TODO

  1. Write TESTS