Skip to content

Commit

Permalink
Add staticLibs option
Browse files Browse the repository at this point in the history
  • Loading branch information
jnordberg committed Aug 25, 2015
1 parent 89885ec commit b42e4da
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions plugin.coffee
Expand Up @@ -16,6 +16,8 @@ module.exports = (env, callback) ->
options.requires ?= {}
options.static ?= []
options.ignore ?= []
options.staticLibs ?= []
options.staticLibsFilename ?= 'scripts/libs.js'
options.extensions ?= ['.js', '.coffee']

# fileGlob for matching - default to provided extensions
Expand All @@ -37,6 +39,24 @@ module.exports = (env, callback) ->
for transform, i in options.transforms
options.transforms[i] = require transform

class BrowserifyStaticLibs extends env.ContentPlugin

constructor: ->
@bundler = browserify()
@bundler.require options.staticLibs

getFilename: -> options.staticLibsFilename

getView: -> (env, locals, contents, templates, callback) ->
if @_cache?
callback null, @_cache
else
stream = @bundler.bundle()
readStream stream, (error, result) =>
unless error?
@_cache = result
callback null, result

class BrowserifyPlugin extends env.ContentPlugin

constructor: (@filepath) ->
Expand All @@ -46,6 +66,8 @@ module.exports = (env, callback) ->

@bundler.add @filepath.full

@bundler.external lib for lib in options.staticLibs

for item in options.externals[@filepath.relative] or []
@bundler.external item

Expand Down Expand Up @@ -108,4 +130,8 @@ module.exports = (env, callback) ->

env.registerContentPlugin 'scripts', options.fileGlob, BrowserifyPlugin

staticLibs = new BrowserifyStaticLibs
env.registerGenerator 'browserify', (contents, callback) ->
callback null, {browserifyLibs: staticLibs}

callback()

0 comments on commit b42e4da

Please sign in to comment.