Skip to content

Commit dc23266

Browse files
committed
switch from browserify to webpack & convert es6 to es5
1 parent 35fb5b9 commit dc23266

File tree

9 files changed

+12516
-8865
lines changed

9 files changed

+12516
-8865
lines changed

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;

devtools/test_dashboard/server.js

+64-36
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@ 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 };
12+
// If interested in development mode
13+
// config.mode = 'development';
1214

1315
var args = minimist(process.argv.slice(2), {});
1416
var PORT = args.port || 3000;
1517
var strict = args.strict;
1618
var mathjax3 = args.mathjax3;
1719
var mathjax3chtml = args.mathjax3chtml;
1820

21+
if(strict) config.entry = './lib/index-strict.js';
22+
1923
// Create server
2024
var server = http.createServer(ecstatic({
2125
root: constants.pathToRoot,
@@ -24,33 +28,70 @@ var server = http.createServer(ecstatic({
2428
cors: true
2529
}));
2630

27-
// Make watchified bundle for plotly.js
28-
var bundlePlotly = makeWatchifiedBundle(strict, function() {
29-
// open up browser window on first bundle callback
30-
open('http://localhost:' + PORT + '/devtools/test_dashboard/index' + (
31-
strict ? '-strict' :
32-
mathjax3 ? '-mathjax3' :
33-
mathjax3chtml ? '-mathjax3chtml' : ''
34-
) + '.html');
35-
});
36-
37-
// Bundle devtools code
38-
var devtoolsPath = path.join(constants.pathToRoot, 'devtools/test_dashboard');
39-
var devtools = browserify(path.join(devtoolsPath, 'devtools.js'), {
40-
transform: [shortcutPaths]
41-
});
42-
4331
// Start the server up!
4432
server.listen(PORT);
4533

46-
// Build and bundle all the things!
34+
// open up browser window on first bundle callback
35+
open('http://localhost:' + PORT + '/devtools/test_dashboard/index' + (
36+
strict ? '-strict' :
37+
mathjax3 ? '-mathjax3' :
38+
mathjax3chtml ? '-mathjax3chtml' : ''
39+
) + '.html');
40+
41+
// mock list
4742
getMockFiles()
4843
.then(readFiles)
4944
.then(createMocksList)
50-
.then(saveToFile)
51-
.then(bundleDevtools)
52-
.then(bundlePlotly);
45+
.then(saveToFile);
5346

47+
// Devtools config
48+
var devtoolsConfig = {};
49+
50+
var devtoolsPath = path.join(constants.pathToRoot, 'devtools/test_dashboard');
51+
devtoolsConfig.entry = path.join(devtoolsPath, 'devtools.js');
52+
53+
devtoolsConfig.output = {
54+
path: config.output.path,
55+
filename: 'test_dashboard-bundle.js',
56+
library: {
57+
name: 'Tabs',
58+
type: 'umd',
59+
umdNamedDefine: true
60+
}
61+
};
62+
63+
devtoolsConfig.target = config.target;
64+
devtoolsConfig.plugins = config.plugins;
65+
devtoolsConfig.optimization = config.optimization;
66+
devtoolsConfig.mode = config.mode;
67+
68+
var compiler;
69+
70+
compiler = webpack(devtoolsConfig);
71+
compiler.run(function(devtoolsErr, devtoolsStats) {
72+
if(devtoolsErr) {
73+
console.log('err:', devtoolsErr);
74+
} else if(devtoolsStats.hasErrors()) {
75+
console.log('stats.errors:', devtoolsStats.errors);
76+
} else {
77+
console.log('success:', devtoolsConfig.output.path + '/' + devtoolsConfig.output.filename);
78+
}
79+
80+
compiler.close(function(closeErr) {
81+
if(!closeErr) {
82+
compiler = webpack(config);
83+
compiler.watch({}, function(err, stats) {
84+
if(err) {
85+
console.log('err:', err);
86+
} else if(stats.hasErrors()) {
87+
console.log('stats.errors:', stats.errors);
88+
} else {
89+
console.log('success:', config.output.path + '/' + config.output.filename);
90+
}
91+
});
92+
}
93+
});
94+
});
5495

5596
function getMockFiles() {
5697
return new Promise(function(resolve, reject) {
@@ -137,16 +178,3 @@ function writeFilePromise(path, contents) {
137178
});
138179
});
139180
}
140-
141-
function bundleDevtools() {
142-
return new Promise(function(resolve, reject) {
143-
devtools.bundle(function(err) {
144-
if(err) {
145-
console.error('Error while bundling!', JSON.stringify(String(err)));
146-
return reject(err);
147-
} else {
148-
return resolve();
149-
}
150-
}).pipe(fs.createWriteStream(constants.pathToTestDashboardBundle));
151-
});
152-
}

0 commit comments

Comments
 (0)