Skip to content
Open
Show file tree
Hide file tree
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
47 changes: 15 additions & 32 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
{
"ecmaFeatures": {
"arrowFunctions": true,
"binaryLiterals": true,
"blockBindings": true,
"classes": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"generators": true,
"modules": false,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"octalLiterals": true,
"regexUFlag": true,
"regexYFlag": true,
"superInFunctions": true,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"globalReturn": true,
"jsx": true
},
"env": {
"browser": true,
"node": true,
"es6": true
"node": true
},
"rules": {
"no-comma-dangle": 2,
Expand Down Expand Up @@ -134,7 +109,7 @@
"comma-spacing": [
1,
{
"before": 0,
"before": false,
"after": true
}
],
Expand All @@ -155,7 +130,7 @@
"key-spacing": [
1,
{
"beforeColon": 0,
"beforeColon": false,
"afterColon": true
}
],
Expand All @@ -178,7 +153,14 @@
"no-trailing-spaces": 2,
"no-underscore-dangle": 0,
"no-wrap-func": 2,
"one-var": 1,
"one-var": [
1,
{
"var": "always",
"let": "never",
"const": "never"
}
],
"operator-assignment": [
2,
"always"
Expand All @@ -205,7 +187,7 @@
"always"
],
"space-before-blocks": 0,
"space-before-function-parentheses": [
"space-before-function-paren": [
1,
"always"
],
Expand All @@ -222,11 +204,12 @@
"space-unary-ops": [
1,
{
"words": 2,
"words": true,
"nonwords": false
}
],
"spaced-line-comment": [
"spaced-comment": [
1,
"always",
{
"exceptions": [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ If `true`, minifies source code and sets debug to true. If object, passed as opt
If `true`, [watchify](https://github.com/substack/watchify) will be used to create a file watcher and speed up subsequent builds.

#### opts.cache
If truthy, will use [browserify-incremental](https://github.com/jsdf/browserify-incremental) to cache the result of a build. This can give you dramatically faster build times if you're not using `opts.watch`.
If truthy, will use [rebundler](https://github.com/bjoerge/rebundler) to cache the result of a build. This can give you dramatically faster build times if you're not using `opts.watch`.

If `opts.cache` is a string, it will be used as the file path to save the cache file to.

Expand Down
39 changes: 25 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict'

var browserify = require('browserify')
, browserifyInc = require('browserify-incremental')
, rebundler = require('rebundler')
, path = require('path')
, fs = require('fs')
, md5 = require('MD5')
, events = require('events')
, mkdirp = require('mkdirp')
, watchify = require('watchify')
Expand All @@ -30,6 +31,8 @@ ctor = module.exports = function atomifyJs (opts, cb) {
, _outputcb
, _buffercb
, browserifyOptions
, persistKey
, cacheChecker
, transforms
, assets
, outputs
Expand Down Expand Up @@ -90,25 +93,33 @@ ctor = module.exports = function atomifyJs (opts, cb) {
// remove the default 600ms delay because speed is tood
// ignoreWatch to true to ignore node_modules
if (opts.watch) _.extend({delay: 0, ignoreWatch: true}, browserifyOptions, watchify.args)
// mixin the required browserifyInc options if we need to cache
if (opts.cache) _.extend(browserifyOptions, browserifyInc.args)

b = browserify(browserifyOptions)

if (opts.cache) {
b = browserifyInc(b
, _.isString(opts.cache) ? {cacheFile: opts.cache} : {}
)
persistKey = md5(opts.entry || opts.entries.toString() || opts.require.toString())

b = browserify(_.extend(browserifyOptions, {
fullPaths: true
}))
emitter.emit('browserify', b)

cacheChecker = rebundler({persist: true, persistKey: persistKey, cacheDir: typeof opts.cache === 'string' ? opts.cache : null}, function rebundle (cache, packageCache) {
b._mdeps.cache = {
deps: cache
, pkgs: packageCache
, mtimes: b._mdeps.cache.mtimes
}
return b
})
}
else {
b = browserify(browserifyOptions)
emitter.emit('browserify', b)
}

emitter.emit('browserify', b)

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

if (opts.watch) {
w.on('update', function onUpdate (ids) {
ids.forEach(function eachId (id) {
emitter.emit('changed', id)
Expand Down Expand Up @@ -225,7 +236,7 @@ ctor = module.exports = function atomifyJs (opts, cb) {
})

// we need to wrap the callback to output an object with all the bundles
return b.bundle(function bundledWithCommon (err, common) {
return (opts.cache ? cacheChecker() : b).bundle(function bundledWithCommon (err, common) {
var hasCallback = _.isFunction(cb)
, out = {}

Expand All @@ -249,7 +260,7 @@ ctor = module.exports = function atomifyJs (opts, cb) {
})
}
// if we don't need to use factor bundle, just browserify!
else return b.bundle(cb)
else return (opts.cache ? cacheChecker() : b).bundle(cb)
}

ctor.emitter = emitter
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,35 @@
],
"license": "MIT",
"dependencies": {
"babelify": "^6.0.2",
"MD5": "^1.2.2",
"babelify": "^6.1.2",
"brfs": "^1.4.0",
"browserify": "^7.1.0",
"browserify-incremental": "^1.5.0",
"ejsify": "^1.0.0",
"envify": "^3.4.0",
"factor-bundle": "^2.4.0",
"factor-bundle": "^2.4.1",
"handlebars": "^2.0.0",
"hbsfy": "^2.2.1",
"jade": "^1.9.2",
"jadeify": "^4.1.0",
"lodash": "^3.6.0",
"minifyify": "^6.3.2",
"mkdirp": "^0.5.0",
"jade": "^1.11.0",
"jadeify": "^4.3.0",
"lodash": "^3.10.0",
"minifyify": "^6.4.0",
"mkdirp": "^0.5.1",
"partialify": "^3.1.2",
"rebundler": "^0.1.0",
"resrcify": "^1.1.0",
"stream-buffers": "^1.1.0",
"watchify": "^2.6.0",
"write-to-path": "^1.0.0"
},
"devDependencies": {
"dmn": "^1.0.10",
"doctoc": "^0.12.0",
"ghooks": "^0.3.0",
"nodemon": "^1.2.1",
"tap-spec": "^1.0.0",
"tape": "^3.0.0"
"doctoc": "^0.14.1",
"eslint": "^0.24.0",
"ghooks": "^0.3.2",
"nodemon": "^1.3.7",
"rimraf": "^2.4.1",
"tap-spec": "^4.0.2",
"tape": "^4.0.0"
}
}
Loading