-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Custom bundle script details #5527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
9fe3255
ca4d557
ba00b93
cbb431e
5aa2234
7de7be9
df8005a
efa9357
9ca5d44
9d34652
0869970
7d0145a
fa35c86
65efc42
b05beef
fc25200
bcb7967
9411d7f
1e21747
34c09c3
6974914
4b0f1da
90bf969
3693985
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ var browserify = require('browserify'); | |
var minify = require('minify-stream'); | ||
var derequire = require('derequire'); | ||
var through = require('through2'); | ||
var exorcist = require('exorcist'); | ||
|
||
var constants = require('./constants'); | ||
var strictD3 = require('./strict_d3'); | ||
|
@@ -22,9 +23,8 @@ var strictD3 = require('./strict_d3'); | |
* - noCompress {boolean} skip attribute meta compression? | ||
* @param {function} cb callback | ||
* | ||
* Outputs one bundle (un-minified) file if opts.pathToMinBundle is omitted | ||
* or opts.debug is true. Otherwise outputs two file: one un-minified bundle and | ||
* one minified bundle. | ||
* Outputs one bundle (un-minified) file if opts.pathToMinBundle is omitted. | ||
* Otherwise outputs two file: one un-minified bundle and one minified bundle. | ||
* | ||
* Logs basename of bundle when completed. | ||
*/ | ||
|
@@ -35,7 +35,8 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) { | |
|
||
var browserifyOpts = {}; | ||
browserifyOpts.standalone = opts.standalone; | ||
browserifyOpts.debug = opts.debug; | ||
var sourceMap = opts.pathToSourceMap; | ||
browserifyOpts.debug = opts.debug || sourceMap; | ||
|
||
if(opts.noCompress) { | ||
browserifyOpts.ignoreTransform = './tasks/compress_attributes.js'; | ||
|
@@ -47,7 +48,7 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) { | |
} | ||
|
||
var b = browserify(pathToIndex, browserifyOpts); | ||
var pending = pathToMinBundle ? 2 : 1; | ||
var pending = (pathToMinBundle && pathToBundle) ? 2 : 1; | ||
|
||
function done() { | ||
if(cb && --pending === 0) cb(null); | ||
|
@@ -71,13 +72,24 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) { | |
}); | ||
} | ||
|
||
bundleStream | ||
.pipe(applyDerequire()) | ||
.pipe(fs.createWriteStream(pathToBundle)) | ||
.on('finish', function() { | ||
logger(pathToBundle); | ||
done(); | ||
}); | ||
if(sourceMap) { | ||
bundleStream | ||
.pipe(applyDerequire()) | ||
.pipe(exorcist(sourceMap)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is generating the sourcemap of the unminified bundle. The real value is in a sourcemap of the minified bundle (which, for clarity, gets extension There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call. Addressed in 7d0145a. |
||
.pipe(fs.createWriteStream(pathToBundle)) | ||
.on('finish', function() { | ||
logger(pathToBundle); | ||
done(); | ||
}); | ||
} else { | ||
bundleStream | ||
.pipe(applyDerequire()) | ||
.pipe(fs.createWriteStream(pathToBundle)) | ||
.on('finish', function() { | ||
logger(pathToBundle); | ||
done(); | ||
}); | ||
} | ||
}; | ||
|
||
function logger(pathToOutput) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels a bit fragile - can we either just make the comma optional in the pattern, or add the comma in
lib/index
so all the lines are equivalent?