Skip to content

Commit

Permalink
Browserify 2.x support
Browse files Browse the repository at this point in the history
  • Loading branch information
jnordberg committed May 15, 2013
1 parent 53a3b76 commit 93ff9e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
7 changes: 4 additions & 3 deletions package.json
@@ -1,11 +1,12 @@
{
"name": "wintersmith-browserify",
"version": "0.1.2",
"version": "0.2.0",
"author": "Johan Nordberg <its@johan-nordberg.com>",
"description": "browserify for witnersmith",
"license": "MIT",
"dependencies": {
"browserify": "1.x.x",
"coffee-script": ">= 1.1.0"
"browserify": "2.13.x",
"coffee-script": ">= 1.1.0",
"caching-coffeeify": "~0.1.1"
}
}
39 changes: 17 additions & 22 deletions plugin.coffee
Expand Up @@ -2,36 +2,31 @@
browserify = require 'browserify'

module.exports = (env, callback) ->
options = env.config.browserify or {}
options.transforms ?= ['caching-coffeeify']
options.debug ?= (env.mode is 'preview')
options.externals ?= {}
options.ignore ?= []

for transform, i in options.transforms
options.transforms[i] = require transform

class BrowserifyPlugin extends env.ContentPlugin

constructor: (@filepath) ->
@bundler = browserify()
@bundler.add @filepath.full
externals = options.externals[@filepath.relative] or []
@bundler.external file for file in externals
@bundler.ignore file for file in options.ignore
@bundler.transform transform for transform in options.transforms

getFilename: ->
env.utils.stripExtension(@filepath.relative) + '.js'

getView: ->
return (env, locals, contents, templates, callback) ->
options =
cache: false
watch: false

for key, opt of env.config.browserify?
options[key] = opt

bundle = browserify options

bundle.addListener 'syntaxError', (error) ->
callback error
# unset callback so we don't call it twice
callback = null

# wrap in try catch since coffeescript parse errors will throw..
try
bundle.addEntry @filepath.full
callback? null, new Buffer bundle.bundle()
catch error
callback? error
getView: -> (env, locals, contents, templates, callback) ->
stream = @bundler.bundle options
callback null, stream

BrowserifyPlugin.fromFile = (filepath, callback) ->
callback null, new BrowserifyPlugin filepath
Expand Down

0 comments on commit 93ff9e0

Please sign in to comment.