Skip to content

Commit

Permalink
Merge pull request #6909 from plotly/build-with-esbuild
Browse files Browse the repository at this point in the history
Switch to `esbuild` for faster builds and also to allow using more modern JavaScript syntax and features
  • Loading branch information
archmoj committed Sep 12, 2024
2 parents 22efc2f + 1b48536 commit bb2b8e6
Show file tree
Hide file tree
Showing 28 changed files with 1,176 additions and 3,928 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
environment:
# Alaska time (arbitrary timezone to test date logic)
TZ: "America/Anchorage"
parallelism: 12
parallelism: 4
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
var fs = require('fs');
var path = require('path');
var http = require('http');
var ecstatic = require('ecstatic');
var open = require('open');
var webpack = require('webpack');
var minimist = require('minimist');

var constants = require('../../tasks/util/constants');
var config = require('../../webpack.config.js');
config.optimization = { minimize: false };
import fs from 'fs';
import path from 'path';
import http from 'http';
import ecstatic from 'ecstatic';
import open from 'open';
import minimist from 'minimist';

import constants from '../../tasks/util/constants.js';
import { build } from 'esbuild';
import config from '../../esbuild-config.js';

var args = minimist(process.argv.slice(2), {});
var PORT = args.port || 3000;
Expand All @@ -21,6 +20,8 @@ var reglTraceList = [
'splom'
];



// Create server
var _static = ecstatic({
root: constants.pathToRoot,
Expand Down Expand Up @@ -57,55 +58,25 @@ var server = http.createServer(function(req, res) {
}
});


// Start the server up!
server.listen(PORT);

// open up browser window
open('http://localhost:' + PORT + '/devtools/regl_codegen/index' + (strict ? '-strict' : '') + '.html');

// Build and bundle all the things!
getMockFiles()
await getMockFiles()
.then(readFiles)
.then(createMocksList)
.then(saveMockListToFile)
.then(saveReglTracesToFile.bind(null, reglTraceList));

// Devtools config
var devtoolsConfig = {};

var devtoolsPath = path.join(constants.pathToRoot, 'devtools/regl_codegen');
devtoolsConfig.entry = path.join(devtoolsPath, 'devtools.js');

devtoolsConfig.output = {
path: config.output.path,
filename: 'regl_codegen-bundle.js',
library: {
name: 'Tabs',
type: 'umd'
}
};

devtoolsConfig.target = config.target;
devtoolsConfig.plugins = config.plugins;
devtoolsConfig.optimization = config.optimization;
devtoolsConfig.mode = 'production';

var compiler;

compiler = webpack(devtoolsConfig);
compiler.run(function(devtoolsErr, devtoolsStats) {
if(devtoolsErr) {
console.log('err:', devtoolsErr);
} else if(devtoolsStats.errors && devtoolsStats.errors.length) {
console.log('stats.errors:', devtoolsStats.errors);
} else {
console.log('success:', devtoolsConfig.output.path + '/' + devtoolsConfig.output.filename);
// Start the server up!
server.listen(PORT);

purgeGeneratedCode(reglTraceList);
}
});
// open up browser window
open('http://localhost:' + PORT + '/devtools/regl_codegen/index' + (strict ? '-strict' : '') + '.html');

var devtoolsPath = path.join(constants.pathToRoot, 'devtools/regl_codegen');
config.entryPoints = [path.join(devtoolsPath, 'devtools.js')];
config.outfile = './build/regl_codegen-bundle.js';
config.sourcemap = false;
config.minify = false;
await build(config);

function getMockFiles() {
return new Promise(function(resolve, reject) {
Expand Down Expand Up @@ -240,18 +211,3 @@ function handleCodegen(data) {
var precompiled = header + imports + exports;
fs.writeFileSync(pathToReglPrecompiledSrc, precompiled);
}


function purgeGeneratedCode(traces) {
var pathToReglCodegenSrc = constants.pathToReglCodegenSrc;

var files = fs.readdirSync(pathToReglCodegenSrc);
files.forEach(function(file) {
fs.unlinkSync(path.join(pathToReglCodegenSrc, file));
});

traces.forEach(function(trace) {
var pathToReglPrecompiledSrc = path.join(constants.pathToSrc, 'traces', trace, 'regl_precompiled.js');
fs.writeFileSync(pathToReglPrecompiledSrc, 'module.exports = {};\n');
});
}
2 changes: 1 addition & 1 deletion devtools/test_dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div id="snapshot"></div>

<script src="../../node_modules/mathjax-v2/MathJax.js?config=TeX-AMS-MML_SVG"></script>
<script charset="utf-8" id="source" src="../../build/plotly.js" type="module"></script>
<script charset="utf-8" id="source" src="../../build/plotly.js"></script>
<script charset="utf-8" src="../../build/test_dashboard-bundle.js"></script>
</body>
</html>
190 changes: 0 additions & 190 deletions devtools/test_dashboard/server.js

This file was deleted.

Loading

0 comments on commit bb2b8e6

Please sign in to comment.