Last active
December 11, 2015 14:48
-
-
Save shesek/4616295 to your computer and use it in GitHub Desktop.
Inline client-side JavaScript with browserify and express
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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