Skip to content

Instantly share code, notes, and snippets.

@shesek
Last active December 11, 2015 14:48
Show Gist options
  • Save shesek/4616295 to your computer and use it in GitHub Desktop.
Save shesek/4616295 to your computer and use it in GitHub Desktop.
Inline client-side JavaScript with browserify and express
browserify = require 'browserify'
client = (mount, fn) -> (browserify { mount }).addEntry 'main.js', body: '(' + fn + ')()'
# Usage:
app = express()
app.use client '/client.js', ->
foo = require './foo'
bar = require 'bar'
foo 123, bar, 456
# /client.js now serves a bundle with the anonymous function as an entry,
# and require()d dependencies are added by browserify.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment