commit 9b565a6375d72932878b16c7d6eeb5fec6d7444f
parent 549104c5a8b9adda09d6fe080b721237c8186e05
Author: Martin von Gagern <gagern@ma.tum.de>
Date: Sat, 7 Jan 2017 01:29:41 +0100
Include babelify step in browserify calls
This allows using ES6 syntax in our code, while maintaining backwards
compatibility for the generated file.
Diffstat:
7 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/.babelrc b/.babelrc
@@ -0,0 +1,6 @@
+{
+ "presets": ["es2015"],
+ "plugins": [
+ "transform-runtime"
+ ]
+}
diff --git a/.eslintrc b/.eslintrc
@@ -76,7 +76,7 @@
"templateStrings": true
},
"env": {
- // "es6": true,
+ "es6": true,
"node": true,
"browser": true
},
diff --git a/Makefile b/Makefile
@@ -13,6 +13,12 @@ dist: build
endif
+NODE := node # pass NODE=nodejs on Debian without package nodejs-legacy
+NODECHK := $(shell $(NODE) ./check-node-version.js)
+ifneq ($(NODECHK),OK)
+$(error "Node not found or wrong version")
+endif
+
# Export these variables for use in contrib Makefiles
export BUILDDIR = $(realpath build)
export BROWSERIFY = $(realpath ./node_modules/.bin/browserify)
@@ -33,7 +39,7 @@ lint: $(NIS) katex.js server.js cli.js $(wildcard src/*.js) $(wildcard test/*.js
./node_modules/.bin/eslint $(filter-out %.stamp,$^)
build/katex.js: katex.js $(wildcard src/*.js) $(NIS)
- $(BROWSERIFY) $< --standalone katex > $@
+ $(BROWSERIFY) -t [ babelify ] $< --standalone katex > $@
build/katex.min.js: build/katex.js
$(UGLIFYJS) < $< > $@
@@ -92,7 +98,7 @@ compress: build/katex.min.js build/katex.min.css
@printf "Total: %6d\n" "${TOTAL}"
serve: $(NIS)
- node server.js
+ $(NODE) server.js
test: $(NIS)
JASMINE_CONFIG_PATH=test/jasmine.json node_modules/.bin/jasmine
diff --git a/check-node-version.js b/check-node-version.js
@@ -0,0 +1,16 @@
+"use strict";
+
+var v = process.version;
+v = v.replace(/^v/,"");
+v = v.split(".");
+v = v.map(function(s){
+ return parseInt(s);
+});
+var a = v[0], b = v[1], c = v[2];
+if (a < 6 || (a == 6 && b < 5)) {
+ console.error("Node 6.5 or later required for development. " +
+ "Version " + process.version + " found");
+ process.exit(1);
+} else {
+ console.log("OK");
+}
diff --git a/contrib/auto-render/Makefile b/contrib/auto-render/Makefile
@@ -6,4 +6,4 @@ $(BUILDDIR)/contrib/auto-render.min.js: $(BUILDDIR)/auto-render.js
$(UGLIFYJS) < $< > $@
$(BUILDDIR)/auto-render.js: auto-render.js
- $(BROWSERIFY) $< --standalone renderMathInElement > $@
+ $(BROWSERIFY) -t [ babelify ] $< --standalone renderMathInElement > $@
diff --git a/package.json b/package.json
@@ -15,6 +15,9 @@
],
"license": "MIT",
"devDependencies": {
+ "babel-plugin-transform-runtime": "^6.15.0",
+ "babel-preset-es2015": "^6.18.0",
+ "babelify": "^7.3.0",
"browserify": "^13.3.0",
"clean-css": "^3.4.23",
"eslint": "^3.13.0",
diff --git a/server.js b/server.js
@@ -2,6 +2,7 @@
var fs = require("fs");
var path = require("path");
+var babelify = require("babelify");
var browserify = require("browserify");
var express = require("express");
var glob = require("glob");
@@ -25,7 +26,9 @@ var serveBrowserified = function(file, standaloneName) {
files = [path.join(__dirname, file)];
}
- var options = {};
+ var options = {
+ transform: [babelify]
+ };
if (standaloneName) {
options.standalone = standaloneName;
}