pegjs/benchmark/server
David Majda 959f20f6e2 Pass benchmark code through Babel before serving it to the browser
This will allow to use ES2015 constructs in benchmark code.

The change required introducing a small server, which serves both PEG.js
and benchmark code passed through Babel and bundled together. This
allowed to convert the benchmark to regular modules and to get rid of
the hackery that was previously needed to make it run both in Node.js
and in the browser.

Note the benchmark no longer exercises the browser version.

See #442.
2016-09-08 14:53:12 +02:00

39 lines
958 B
JavaScript
Executable file

#!/usr/bin/env node
/* eslint-env node */
/* eslint no-console: 0 */
/*
* Small server whose main purpose is to ensure that both the benchmarked code
* and the benchmark get passed through Babel & Browserify before they are
* served to the browser.
*/
var express = require("express"),
logger = require("morgan"),
glob = require("glob"),
browserify = require("browserify"),
babelify = require("babelify");
var app = express();
app.use(logger("dev"));
app.use(express.static(__dirname));
app.use("/examples", express.static(__dirname + "/../examples"));
app.get("/bundle.js", function(req, res) {
var files = glob.sync(__dirname + "/**/*.js", {
ignore: __dirname + "/vendor/**/*"
});
browserify(files)
.transform(babelify, { presets: "es2015", compact: false })
.bundle()
.pipe(res);
});
app.listen(8000, function() {
console.log("Benchmark server running at http://localhost:8000...");
});