Skip to content

Instantly share code, notes, and snippets.

@killercup
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killercup/8868263 to your computer and use it in GitHub Desktop.
Save killercup/8868263 to your computer and use it in GitHub Desktop.
Browserify Structure

Client Side Module System

Goal: Use some modules (React components) on client side and server

Directory Structure

/client/
  app.coffee
  routes.coffee # backbone.Router
  models/
    user.coffee # backbone.Model
/lib/
  components/
    start/
      index.coffee # react component
      blocks.coffee # react component used by index.coffee
    profile/
      index.coffee
      settings.coffee
/server/
  index.coffee
  routes.coffee # express.js
  sessions.coffee
  models/
    user.coffee # mongoose.Schema

Client Side: Files after Compilation

/public/
  vendor-612d3d.js # backbone, lodash, react
  app-a81d3d.js # app specific files
  index.html

To accomplish this, browserify needs to be configured in a way that libraries are written to their own file (vendor.js) and used as external dependencies for app.js.

Additionally, one should be able to overwrite the library files with browser-specific ones, e.g. by using the minified compiled versions of backbone and react from bower and to replace underscore with lodash.

For an example configuration, see this StackOverflow answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment