Include babelify step in browserify calls
This allows using ES6 syntax in our code, while maintaining backwards compatibility for the generated file.
This commit is contained in:
parent
549104c5a8
commit
9b565a6375
6
.babelrc
Normal file
6
.babelrc
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"presets": ["es2015"],
|
||||
"plugins": [
|
||||
"transform-runtime"
|
||||
]
|
||||
}
|
|
@ -76,7 +76,7 @@
|
|||
"templateStrings": true
|
||||
},
|
||||
"env": {
|
||||
// "es6": true,
|
||||
"es6": true,
|
||||
"node": true,
|
||||
"browser": true
|
||||
},
|
||||
|
|
10
Makefile
10
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
|
||||
|
|
16
check-node-version.js
Normal file
16
check-node-version.js
Normal file
|
@ -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");
|
||||
}
|
|
@ -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 > $@
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user