-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Introducing partial dist bundles #740
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 3 commits
3616db9
91bf6af
23fa754
af27a0e
c4f9292
dcb1229
34460c3
9bead06
f95f9aa
5bc1167
7b0a017
7a43781
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
|
||
var Core = require('./core'); | ||
|
||
Core.register([ | ||
require('./bar'), | ||
require('./pie') | ||
]); | ||
|
||
module.exports = Core; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var Core = require('./core'); | ||
|
||
Core.register([ | ||
require('./bar'), | ||
require('./box'), | ||
require('./heatmap'), | ||
require('./histogram'), | ||
require('./histogram2d'), | ||
require('./histogram2dcontour'), | ||
require('./pie'), | ||
require('./contour'), | ||
require('./scatterternary') | ||
]); | ||
|
||
module.exports = Core; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var Core = require('./core'); | ||
|
||
Core.register([ | ||
require('./scattergeo'), | ||
require('./choropleth') | ||
]); | ||
|
||
module.exports = Core; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var Core = require('./core'); | ||
|
||
// Load all trace modules | ||
Core.register([ | ||
require('./scattergl'), | ||
require('./heatmapgl'), | ||
require('./contourgl') | ||
]); | ||
|
||
module.exports = Core; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var Core = require('./core'); | ||
|
||
Core.register([ | ||
require('./scatter3d'), | ||
require('./surface'), | ||
require('./mesh3d') | ||
]); | ||
|
||
module.exports = Core; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var Core = require('./core'); | ||
|
||
Core.register([ | ||
require('./scattermapbox') | ||
]); | ||
|
||
module.exports = Core; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var browserify = require('browserify'); | ||
var UglifyJS = require('uglify-js'); | ||
|
@@ -35,41 +36,73 @@ catch(e) { | |
|
||
|
||
// Browserify plotly.js | ||
browserify(constants.pathToPlotlyIndex, { | ||
debug: DEV, | ||
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDist, { | ||
standalone: 'Plotly', | ||
transform: [compressAttributes] | ||
}) | ||
.bundle(function(err, buf) { | ||
if(err) throw err; | ||
|
||
// generate plotly.min.js | ||
if(!DEV) { | ||
fs.writeFile( | ||
constants.pathToPlotlyDistMin, | ||
UglifyJS.minify(buf.toString(), constants.uglifyOptions).code | ||
); | ||
} | ||
}) | ||
.pipe(fs.createWriteStream(constants.pathToPlotlyDist)); | ||
|
||
debug: DEV, | ||
pathToMinBundle: constants.pathToPlotlyDistMin | ||
}); | ||
|
||
// Browserify the geo assets | ||
browserify(constants.pathToPlotlyGeoAssetsSrc, { | ||
_bundle(constants.pathToPlotlyGeoAssetsSrc, constants.pathToPlotlyGeoAssetsDist, { | ||
standalone: 'PlotlyGeoAssets' | ||
}) | ||
.bundle(function(err) { | ||
if(err) throw err; | ||
}) | ||
.pipe(fs.createWriteStream(constants.pathToPlotlyGeoAssetsDist)); | ||
|
||
}); | ||
|
||
// Browserify the plotly.js with meta | ||
browserify(constants.pathToPlotlyIndex, { | ||
debug: DEV, | ||
standalone: 'Plotly' | ||
}) | ||
.bundle(function(err) { | ||
if(err) throw err; | ||
}) | ||
.pipe(fs.createWriteStream(constants.pathToPlotlyDistWithMeta)); | ||
_bundle(constants.pathToPlotlyIndex, constants.pathToPlotlyDistWithMeta, { | ||
standalone: 'Plotly', | ||
debug: DEV | ||
}); | ||
|
||
// Browserify the plotly.js partial bundles | ||
constants.partialBundleNames.forEach(function(name) { | ||
var pathToIndex = path.join(constants.pathToLib, 'index-' + name + '.js'), | ||
pathToBundle = path.join(constants.pathToDist, 'plotly-' + name + '.js'), | ||
pathToMinBundle = path.join(constants.pathToDist, 'plotly-' + name + '.min.js'); | ||
|
||
_bundle(pathToIndex, pathToBundle, { | ||
standalone: 'Plotly', | ||
debug: DEV, | ||
pathToMinBundle: pathToMinBundle | ||
}); | ||
}); | ||
|
||
function _bundle(pathToIndex, pathToBundle, opts) { | ||
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. Just a thought: what about moving this bundle function to its own file and exporting it? Then Other alternative is that a standalone bundler would implement this and get required by 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.
I thought about too. But I think it's worth spending more time perfecting our bundling scripts until we decide if/when/how we expose a bundler module.
This would get my vote at the moment. |
||
opts = opts || {}; | ||
|
||
// do we output a minified file? | ||
var pathToMinBundle = opts.pathToMinBundle, | ||
outputMinified = !!pathToMinBundle && !opts.debug; | ||
|
||
var browserifyOpts = {}; | ||
browserifyOpts.standalone = opts.standalone; | ||
browserifyOpts.debug = opts.debug; | ||
browserifyOpts.transform = outputMinified ? [compressAttributes] : []; | ||
|
||
var b = browserify(pathToIndex, browserifyOpts), | ||
bundleWriteStream = fs.createWriteStream(pathToBundle); | ||
|
||
bundleWriteStream.on('finish', function() { | ||
logger(pathToBundle); | ||
}); | ||
|
||
b.bundle(function(err, buf) { | ||
if(err) throw err; | ||
|
||
if(outputMinified) { | ||
var minifiedCode = UglifyJS.minify(buf.toString(), constants.uglifyOptions).code; | ||
|
||
fs.writeFile(pathToMinBundle, minifiedCode, function(err) { | ||
if(err) throw err; | ||
|
||
logger(pathToMinBundle); | ||
}); | ||
} | ||
}) | ||
.pipe(bundleWriteStream); | ||
} | ||
|
||
function logger(pathToOutput) { | ||
var log = 'ok ' + path.basename(pathToOutput); | ||
|
||
console.log(log); | ||
} |
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.
Maybe worth an inline comment to note that
Core
pulls in scatter. If I were looking to bundle my own, I'd start by copy/pasting this file, and I had to track down the inclusion of scatter.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.
(To clarify, I had to stop and think whether core pulled it in or whether it was something pulled in indirectly by bar/pie.)