Serve files with and without babelify step
As babelify is slow, it may be desriable to not run it during development. This is OK if the browser is recent enough to understand ES6 natively. (This does not include current Firefox due to it having problems with for(const … in …), https://bugzilla.mozilla.org/show_bug.cgi?id=1094995.) For older browsers, or to check issues possibly introduced by babelify, adding /babel as the first component of the path will switch to a version which has been processed by babelify. This is also used for screenshots.
This commit is contained in:
parent
bd9db332d2
commit
38ba9f9187
|
@ -291,7 +291,7 @@ function findHostIP() {
|
||||||
}
|
}
|
||||||
if (katexIP !== "*any*" || katexURL) {
|
if (katexIP !== "*any*" || katexURL) {
|
||||||
if (!katexURL) {
|
if (!katexURL) {
|
||||||
katexURL = "http://" + katexIP + ":" + katexPort + "/";
|
katexURL = "http://" + katexIP + ":" + katexPort + "/babel/";
|
||||||
console.log("KaTeX URL is " + katexURL);
|
console.log("KaTeX URL is " + katexURL);
|
||||||
}
|
}
|
||||||
process.nextTick(takeScreenshots);
|
process.nextTick(takeScreenshots);
|
||||||
|
@ -303,7 +303,7 @@ function findHostIP() {
|
||||||
app.get("/ss-connect.js", function(req, res, next) {
|
app.get("/ss-connect.js", function(req, res, next) {
|
||||||
if (!katexURL) {
|
if (!katexURL) {
|
||||||
katexIP = req.query.ip;
|
katexIP = req.query.ip;
|
||||||
katexURL = "http://" + katexIP + ":" + katexPort + "/";
|
katexURL = "http://" + katexIP + ":" + katexPort + "/babel/";
|
||||||
console.log("KaTeX URL is " + katexURL);
|
console.log("KaTeX URL is " + katexURL);
|
||||||
process.nextTick(takeScreenshots);
|
process.nextTick(takeScreenshots);
|
||||||
}
|
}
|
||||||
|
|
57
server.js
57
server.js
|
@ -15,7 +15,7 @@ if (require.main === module) {
|
||||||
":date[iso] :method :url HTTP/:http-version - :status"));
|
":date[iso] :method :url HTTP/:http-version - :status"));
|
||||||
}
|
}
|
||||||
|
|
||||||
var serveBrowserified = function(file, standaloneName) {
|
function serveBrowserified(file, standaloneName, doBabelify) {
|
||||||
return function(req, res, next) {
|
return function(req, res, next) {
|
||||||
let files;
|
let files;
|
||||||
if (Array.isArray(file)) {
|
if (Array.isArray(file)) {
|
||||||
|
@ -26,9 +26,10 @@ var serveBrowserified = function(file, standaloneName) {
|
||||||
files = [path.join(__dirname, file)];
|
files = [path.join(__dirname, file)];
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = {
|
const options = {};
|
||||||
transform: [babelify]
|
if (doBabelify) {
|
||||||
};
|
options.transform = [babelify];
|
||||||
|
}
|
||||||
if (standaloneName) {
|
if (standaloneName) {
|
||||||
options.standalone = standaloneName;
|
options.standalone = standaloneName;
|
||||||
}
|
}
|
||||||
|
@ -43,22 +44,32 @@ var serveBrowserified = function(file, standaloneName) {
|
||||||
res.send(body);
|
res.send(body);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
app.get("/katex.js", serveBrowserified("katex", "katex"));
|
function twoBrowserified(url, file, standaloneName) {
|
||||||
app.use("/test/jasmine",
|
app.get(url, serveBrowserified(file, standaloneName, false));
|
||||||
express["static"](
|
app.get("/babel" + url, serveBrowserified(file, standaloneName, true));
|
||||||
path.dirname(
|
}
|
||||||
require.resolve("jasmine-core/lib/jasmine-core/jasmine.js")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
app.get("/test/katex-spec.js", serveBrowserified("test/*[Ss]pec.js"));
|
|
||||||
app.get("/contrib/auto-render/auto-render.js",
|
|
||||||
serveBrowserified("contrib/auto-render/auto-render",
|
|
||||||
"renderMathInElement"));
|
|
||||||
|
|
||||||
app.get("/katex.css", function(req, res, next) {
|
function twoUse(url, handler) {
|
||||||
|
app.use(url, handler);
|
||||||
|
app.use("/babel" + url, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
function twoStatic(url, file) {
|
||||||
|
twoUse(url, express.static(path.join(__dirname, file)));
|
||||||
|
}
|
||||||
|
|
||||||
|
twoBrowserified("/katex.js", "katex", "katex");
|
||||||
|
twoUse("/test/jasmine", express.static(path.dirname(
|
||||||
|
require.resolve("jasmine-core/lib/jasmine-core/jasmine.js"))));
|
||||||
|
twoBrowserified("/test/katex-spec.js", "test/*[Ss]pec.js");
|
||||||
|
twoBrowserified(
|
||||||
|
"/contrib/auto-render/auto-render.js",
|
||||||
|
"contrib/auto-render/auto-render",
|
||||||
|
"renderMathInElement");
|
||||||
|
|
||||||
|
twoUse("/katex.css", function(req, res, next) {
|
||||||
const lessfile = path.join(__dirname, "static", "katex.less");
|
const lessfile = path.join(__dirname, "static", "katex.less");
|
||||||
fs.readFile(lessfile, {encoding: "utf8"}, function(err, data) {
|
fs.readFile(lessfile, {encoding: "utf8"}, function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -82,12 +93,10 @@ app.get("/katex.css", function(req, res, next) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(express["static"](path.join(__dirname, "static")));
|
twoStatic("", "static");
|
||||||
app.use(express["static"](path.join(__dirname, "build")));
|
twoStatic("", "build");
|
||||||
app.use("/test", express["static"](path.join(__dirname, "test")));
|
twoStatic("/test", "test");
|
||||||
app.use("/contrib", express["static"](path.join(__dirname, "contrib")));
|
twoStatic("/contrib", "contrib");
|
||||||
// app.use("/unicode-fonts",
|
|
||||||
// express["static"](path.join(__dirname, "static", "unicode-fonts")));
|
|
||||||
|
|
||||||
app.use(function(err, req, res, next) {
|
app.use(function(err, req, res, next) {
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Screenshotter test</title>
|
<title>Screenshotter test</title>
|
||||||
<script src="/katex.js" type="text/javascript"></script>
|
<script src="../../katex.js" type="text/javascript"></script>
|
||||||
<link href="/katex.css" rel="stylesheet" type="text/css">
|
<link href="../../katex.css" rel="stylesheet" type="text/css">
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
#math, #pre, #post {
|
#math, #pre, #post {
|
||||||
font-size: 4em;
|
font-size: 4em;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user