Skip to content

Commit 369f013

Browse files
authored
Merge pull request #6355 from plotly/webpack
Switch from `browserify` to `webpack` in order to be able to use most recent ES modules & allow JavaScript syntax beyond `ES5`
2 parents 9014a11 + 458921f commit 369f013

26 files changed

+17649
-12270
lines changed

.circleci/config.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,7 @@ jobs:
404404
name: Test plotly.min.js import using requirejs
405405
command: npm run test-requirejs
406406
- run:
407-
name: Test plotly bundles againt unexpected characters
408-
command: npm run no-bad-char
409-
- run:
410-
name: Display function constructors in plotly.js bundle
411-
command: npm run log-new-func
412-
- run:
413-
name: Test certain bundles against function constructors
407+
name: Display function constructors in all bundles
414408
command: npm run no-new-func
415409
- run:
416410
name: Test plotly bundles against es6

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ build/*
44
!build/plotcss.js
55
!build/README.md
66

7+
dist/*.LICENSE.txt
8+
79
npm-debug.log*
810
*.sublime*
911
*~

BUILDING.md

-35
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,6 @@ Depending on your needs you may require/import one of [the distributed plotly.js
33

44
The sections below provide additional info in respect to alternative building frameworks.
55

6-
## Browserify example
7-
8-
Given source file:
9-
```js
10-
// file: index.js
11-
var Plotly = require('plotly.js-dist-min');
12-
// ....
13-
```
14-
15-
then simply run
16-
17-
```sh
18-
browserify index.js > bundle.js
19-
```
20-
21-
---
22-
## Webpack
23-
24-
For plotly.js to build with Webpack you will need to install [[email protected]+](https://github.com/hughsk/ify-loader) and add it to your `webpack.config.json`. This adds Browserify transform compatibility to Webpack which is necessary for some plotly.js dependencies.
25-
26-
A repo that demonstrates how to build plotly.js with Webpack can be found [here](https://github.com/plotly/plotly-webpack). In short add `ify-loader` to the `module` section in your `webpack.config.js`:
27-
28-
```js
29-
...
30-
module: {
31-
rules: [
32-
{
33-
test: /\.js$/,
34-
loader: 'ify-loader'
35-
}
36-
]
37-
},
38-
...
39-
```
40-
416
---
427
## Angular CLI
438

CONTRIBUTING.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ npm run pretest
116116
npm start
117117
```
118118

119-
This command bundles up the source files with source maps using
120-
[browserify](https://github.com/substack/node-browserify), starts a
121-
[watchify](https://github.com/substack/watchify) file watcher (making your
122-
dev plotly.js bundle update every time a source file is saved) and opens up a
123-
tab in your browser.
119+
This command bundles up the source files and opens up a tab in your browser.
124120

125121
#### Step 6: Open up the console and start developing
126122

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ There are two kinds of plotly.js bundles:
108108

109109
---
110110
## Alternative ways to load and build plotly.js
111-
If your library needs to bundle or directly load [plotly.js/lib/index.js](https://github.com/plotly/plotly.js/blob/master/lib/index.js) or parts of its modules similar to [index-basic](https://github.com/plotly/plotly.js/blob/master/lib/index-basic.js) in some other way than via an official or a custom bundle, or in case you want to tweak the default build configurations of `browserify` or `webpack`, etc. then please visit [`BUILDING.md`](https://github.com/plotly/plotly.js/blob/master/BUILDING.md).
111+
If your library needs to bundle or directly load [plotly.js/lib/index.js](https://github.com/plotly/plotly.js/blob/master/lib/index.js) or parts of its modules similar to [index-basic](https://github.com/plotly/plotly.js/blob/master/lib/index-basic.js) in some other way than via an official or a custom bundle, or in case you want to tweak the default build configurations, then please visit [`BUILDING.md`](https://github.com/plotly/plotly.js/blob/master/BUILDING.md).
112112

113113
---
114114
## Documentation

devtools/regl_codegen/devtools.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
var mocks = require('../../build/test_dashboard_mocks.json');
66
var reglTraces = require('../../build/regl_traces.json');
7-
var Lib = require('@src/lib');
7+
var Lib = require('../../src/lib');
88

99
// Our gracious testing object
1010
var Tabs = {
@@ -158,3 +158,5 @@ function handleOnLoad() {
158158
window.close();
159159
});
160160
}
161+
162+
module.exports = Tabs;

devtools/regl_codegen/server.js

+48-39
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@ var path = require('path');
33
var http = require('http');
44
var ecstatic = require('ecstatic');
55
var open = require('open');
6-
var browserify = require('browserify');
6+
var webpack = require('webpack');
77
var minimist = require('minimist');
88

99
var constants = require('../../tasks/util/constants');
10-
var makeWatchifiedBundle = require('../../tasks/util/watchified_bundle');
11-
var shortcutPaths = require('../../tasks/util/shortcut_paths');
10+
var config = require('../../webpack.config.js');
11+
config.optimization = { minimize: false };
1212

1313
var args = minimist(process.argv.slice(2), {});
1414
var PORT = args.port || 3000;
1515
var strict = args.strict;
1616

17+
var reglTraceList = [
18+
'parcoords',
19+
'scattergl',
20+
'scatterpolargl',
21+
'splom'
22+
];
23+
1724
// Create server
1825
var static = ecstatic({
1926
root: constants.pathToRoot,
@@ -51,38 +58,53 @@ var server = http.createServer(function(req, res) {
5158
});
5259

5360

54-
// Make watchified bundle for plotly.js
55-
var bundlePlotly = makeWatchifiedBundle(strict, function() {
56-
// open up browser window on first bundle callback
57-
open('http://localhost:' + PORT + '/devtools/regl_codegen/index' + (strict ? '-strict' : '') + '.html');
58-
});
59-
60-
// Bundle devtools code
61-
var devtoolsPath = path.join(constants.pathToRoot, 'devtools/regl_codegen');
62-
var devtools = browserify(path.join(devtoolsPath, 'devtools.js'), {
63-
transform: [shortcutPaths]
64-
});
65-
6661
// Start the server up!
6762
server.listen(PORT);
6863

69-
var reglTraceList = [
70-
'parcoords',
71-
'scattergl',
72-
'scatterpolargl',
73-
'splom'
74-
];
75-
76-
purgeGeneratedCode(reglTraceList);
64+
// open up browser window
65+
open('http://localhost:' + PORT + '/devtools/regl_codegen/index' + (strict ? '-strict' : '') + '.html');
7766

7867
// Build and bundle all the things!
7968
getMockFiles()
8069
.then(readFiles)
8170
.then(createMocksList)
8271
.then(saveMockListToFile)
83-
.then(saveReglTracesToFile.bind(null, reglTraceList))
84-
.then(bundleDevtools)
85-
.then(bundlePlotly);
72+
.then(saveReglTracesToFile.bind(null, reglTraceList));
73+
74+
// Devtools config
75+
var devtoolsConfig = {};
76+
77+
var devtoolsPath = path.join(constants.pathToRoot, 'devtools/regl_codegen');
78+
devtoolsConfig.entry = path.join(devtoolsPath, 'devtools.js');
79+
80+
devtoolsConfig.output = {
81+
path: config.output.path,
82+
filename: 'regl_codegen-bundle.js',
83+
library: {
84+
name: 'Tabs',
85+
type: 'umd'
86+
}
87+
};
88+
89+
devtoolsConfig.target = config.target;
90+
devtoolsConfig.plugins = config.plugins;
91+
devtoolsConfig.optimization = config.optimization;
92+
devtoolsConfig.mode = 'production';
93+
94+
var compiler;
95+
96+
compiler = webpack(devtoolsConfig);
97+
compiler.run(function(devtoolsErr, devtoolsStats) {
98+
if(devtoolsErr) {
99+
console.log('err:', devtoolsErr);
100+
} else if(devtoolsStats.errors && devtoolsStats.errors.length) {
101+
console.log('stats.errors:', devtoolsStats.errors);
102+
} else {
103+
console.log('success:', devtoolsConfig.output.path + '/' + devtoolsConfig.output.filename);
104+
105+
purgeGeneratedCode(reglTraceList);
106+
}
107+
});
86108

87109

88110
function getMockFiles() {
@@ -178,19 +200,6 @@ function writeFilePromise(path, contents) {
178200
});
179201
}
180202

181-
function bundleDevtools() {
182-
return new Promise(function(resolve, reject) {
183-
devtools.bundle(function(err) {
184-
if(err) {
185-
console.error('Error while bundling!', JSON.stringify(String(err)));
186-
return reject(err);
187-
} else {
188-
return resolve();
189-
}
190-
}).pipe(fs.createWriteStream(constants.pathToReglCodegenBundle));
191-
});
192-
}
193-
194203
function handleCodegen(data) {
195204
var trace = data.trace;
196205
var generated = data.generated;

devtools/test_dashboard/devtools.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
var Fuse = require('fuse.js/dist/fuse.common.js');
66
var mocks = require('../../build/test_dashboard_mocks.json');
77
var credentials = require('../../build/credentials.json');
8-
var Lib = require('@src/lib');
8+
var Lib = require('../../src/lib');
99

1010
require('./perf');
1111

@@ -268,3 +268,5 @@ function handleOnLoad() {
268268
Tabs.setPlotConfig();
269269
plotFromHash();
270270
}
271+
272+
module.exports = Tabs;

0 commit comments

Comments
 (0)