-
-
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 all 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,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 Plotly = require('./core'); | ||
|
||
Plotly.register([ | ||
require('./bar'), | ||
require('./pie') | ||
]); | ||
|
||
module.exports = Plotly; |
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 Plotly = require('./core'); | ||
|
||
Plotly.register([ | ||
require('./bar'), | ||
require('./box'), | ||
require('./heatmap'), | ||
require('./histogram'), | ||
require('./histogram2d'), | ||
require('./histogram2dcontour'), | ||
require('./pie'), | ||
require('./contour'), | ||
require('./scatterternary') | ||
]); | ||
|
||
module.exports = Plotly; |
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 Plotly = require('./core'); | ||
|
||
Plotly.register([ | ||
require('./scattergeo'), | ||
require('./choropleth') | ||
]); | ||
|
||
module.exports = Plotly; |
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 Plotly = require('./core'); | ||
|
||
Plotly.register([ | ||
require('./scattergl'), | ||
require('./heatmapgl'), | ||
require('./contourgl') | ||
]); | ||
|
||
module.exports = Plotly; |
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 Plotly = require('./core'); | ||
|
||
Plotly.register([ | ||
require('./scatter3d'), | ||
require('./surface'), | ||
require('./mesh3d') | ||
]); | ||
|
||
module.exports = Plotly; |
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 Plotly = require('./core'); | ||
|
||
Plotly.register([ | ||
require('./scattermapbox') | ||
]); | ||
|
||
module.exports = Plotly; |
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'); | ||
|
@@ -28,48 +29,76 @@ try { | |
} | ||
catch(e) { | ||
throw new Error([ | ||
'build/ is missing a or more files', | ||
'build/ is missing one or more files', | ||
'Please run `npm run preprocess` first' | ||
].join('\n')); | ||
} | ||
|
||
|
||
// 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.partialBundlePaths.forEach(function(pathObj) { | ||
_bundle(pathObj.index, pathObj.dist, { | ||
standalone: 'Plotly', | ||
debug: DEV, | ||
pathToMinBundle: pathObj.distMin | ||
}); | ||
}); | ||
|
||
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.
I'd support a comment here noting that scatter is included in core. The first time I read through this, I was wondering if maybe bar or pie were cartesian and pulled in scatter through that (or some other magic). It's not that hard to figure out, but maybe just a nice sign-post if these are the template for creating your own. See: https://github.com/plotly/plotly.js/blob/master/src/plotly.js#L107-L108
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.
I'd vote 👎 on adding a comment here (in all the other index files) to avoid making them obsolete when we'll strip more things for the
./core
.I would prefer pointing users to the
dist/README.md
file wherecoreModules
are listed: