Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ var browserify = require('browserify')
, _ = require('lodash')
, minifyify = require('minifyify')
, resrcify = require('resrcify')
, factorBundle = require('factor-bundle')
, ctor

require('factor-bundle')

ctor = module.exports = function atomifyJs (opts, cb) {
var outputPath
, outputDir
Expand All @@ -35,7 +34,6 @@ ctor = module.exports = function atomifyJs (opts, cb) {
, assets
, outputs
, b
, w

if (Array.isArray(opts)) opts = {entries: opts}
if (typeof opts === 'string') opts = {entries: [opts]}
Expand Down Expand Up @@ -105,20 +103,20 @@ ctor = module.exports = function atomifyJs (opts, cb) {
emitter.emit('browserify', b)

if (opts.watch) {
w = watchify(b)
emitter.emit('watchify', w)
b = watchify(b)
emitter.emit('watchify', b)
}

if (opts.watch) {
w.on('update', function onUpdate (ids) {
b.on('update', function onUpdate (ids) {
ids.forEach(function eachId (id) {
emitter.emit('changed', id)
})

w.bundle(cb)
rebundle()
})

w.on('time', function onTime (time) {
b.on('time', function onTime (time) {
emitter.emit('bundle', time)
})
}
Expand Down Expand Up @@ -200,6 +198,9 @@ ctor = module.exports = function atomifyJs (opts, cb) {
b.external(opts.external)
}

return rebundle()

function rebundle() {
// if we've got the common option, we want to use factor bundle
if (opts.common === true){
if (opts.entries.length < 2) {
Expand All @@ -221,7 +222,7 @@ ctor = module.exports = function atomifyJs (opts, cb) {
})

// setup factor bundle, pass in our streamable-buffers as the output source
b.plugin('factor-bundle', {
b.plugin(factorBundle, {
o: _.values(outputs)
})

Expand Down Expand Up @@ -251,6 +252,7 @@ ctor = module.exports = function atomifyJs (opts, cb) {
}
// if we don't need to use factor bundle, just browserify!
else return b.bundle(cb)
}
}

ctor.emitter = emitter