From d18a8090b12a59cfd21b0ee9d59c04111cee7241 Mon Sep 17 00:00:00 2001 From: rr- Date: Wed, 13 Apr 2016 19:02:21 +0200 Subject: [PATCH] client/build: transpile ES6 for older browsers --- client/.babelrc | 1 + client/build.js | 7 ++++++- client/js/util/polyfill.js | 2 ++ client/package.json | 3 +++ config.yaml.dist | 3 ++- 5 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 client/.babelrc diff --git a/client/.babelrc b/client/.babelrc new file mode 100644 index 00000000..9d8d5165 --- /dev/null +++ b/client/.babelrc @@ -0,0 +1 @@ +{ "presets": ["es2015"] } diff --git a/client/build.js b/client/build.js index 81fc1893..4a13fcb1 100644 --- a/client/build.js +++ b/client/build.js @@ -102,11 +102,16 @@ function bundleCss() { } function bundleJs(config) { + const babelify = require('babelify'); const browserify = require('browserify'); const uglifyjs = require('uglify-js'); glob('./js/**/*.js', {}, function(er, files) { const outputFile = fs.createWriteStream('./public/bundle.min.js'); - browserify({debug: config.debug}).add(files).bundle().pipe(outputFile); + let b = browserify({debug: config.debug}); + if (config.transpile) { + b = b.transform(babelify); + } + b.add(files).bundle().pipe(outputFile); outputFile.on('finish', function() { if (!config.debug) { const result = uglifyjs.minify('./public/bundle.min.js'); diff --git a/client/js/util/polyfill.js b/client/js/util/polyfill.js index 5e6101f7..01a81489 100644 --- a/client/js/util/polyfill.js +++ b/client/js/util/polyfill.js @@ -1,5 +1,7 @@ 'use strict'; +require('babel-polyfill'); + const keys = Reflect.ownKeys; const reduce = Function.bind.call(Function.call, Array.prototype.reduce); const concat = Function.bind.call(Function.call, Array.prototype.concat); diff --git a/client/package.json b/client/package.json index 8f8fca2c..40a1b231 100644 --- a/client/package.json +++ b/client/package.json @@ -6,6 +6,9 @@ "watch": "watch 'npm run build' html js css img --wait=0 --ignoreDotFiles" }, "dependencies": { + "babel-polyfill": "^6.7.4", + "babel-preset-es2015": "^6.6.0", + "babelify": "^7.2.0", "browserify": "^13.0.0", "camelcase": "^2.1.1", "csso": "^1.8.0", diff --git a/config.yaml.dist b/config.yaml.dist index 4ff936e4..df2a943c 100644 --- a/config.yaml.dist +++ b/config.yaml.dist @@ -2,7 +2,8 @@ # and override only what you need. name: szurubooru -debug: 0 +debug: 0 # generate source maps for JS debugging? +transpile: 1 # generate bigger JS to support older browsers? secret: change api_url: # where frontend connects to, example: http://api.example.com/ base_url: # used to form links to frontend, example: http://example.com/