client/build: remove babel when not transpiling

This commit is contained in:
rr- 2016-05-20 23:10:45 +02:00
parent 69fe8ec31a
commit 249d6073c0
4 changed files with 21 additions and 44 deletions

View file

@ -1,5 +1,5 @@
{
"preset": "google",
"fileExtensions": [".js", "jscs"],
"validateIndentation": 4,
preset: "google",
fileExtensions: [".js", "jscs"],
validateIndentation: 4,
}

View file

@ -117,7 +117,6 @@ function writeJsBundle(b, path, message, compress) {
}
function bundleJs(config) {
const babelify = require('babelify');
const browserify = require('browserify');
const external = [
'lodash',
@ -126,7 +125,6 @@ function bundleJs(config) {
'js-cookie',
'page',
'nprogress',
'babel-polyfill',
];
glob('./js/**/*.js', {}, (er, files) => {
if (!process.argv.includes('--no-vendor-js')) {
@ -134,6 +132,9 @@ function bundleJs(config) {
for (let lib of external) {
b.require(lib);
}
if (config.transpile) {
b.add(require.resolve('babel-polyfill'));
}
writeJsBundle(
b, './public/vendor.min.js', 'Bundled vendor JS', true);
}
@ -142,7 +143,7 @@ function bundleJs(config) {
let outputFile = fs.createWriteStream('./public/app.min.js');
let b = browserify({debug: config.debug});
if (config.transpile) {
b = b.transform(babelify);
b = b.transform('babelify');
}
writeJsBundle(
b.external(external).add(files),

View file

@ -14,15 +14,15 @@ const UsersHeaderView = require('../views/users_header_view.js');
const UsersPageView = require('../views/users_page_view.js');
const EmptyView = require('../views/empty_view.js');
const rankNames = {
anonymous: 'Anonymous',
restricted: 'Restricted user',
regular: 'Regular user',
power: 'Power user',
moderator: 'Moderator',
administrator: 'Administrator',
nobody: 'Nobody',
};
const rankNames = new Map([
['anonymous', 'Anonymous'],
['restricted', 'Restricted user'],
['regular', 'Regular user'],
['power', 'Power user'],
['moderator', 'Moderator'],
['administrator', 'Administrator'],
['nobody', 'Nobody'],
]);
class UsersController {
constructor() {
@ -96,7 +96,7 @@ class UsersController {
next();
} else {
api.get('/user/' + ctx.params.name).then(response => {
response.user.rankName = rankNames[response.user.rank];
response.user.rankName = rankNames.get(response.user.rank);
ctx.state.user = response.user;
ctx.save();
this._cachedUser = response.user;
@ -228,7 +228,7 @@ class UsersController {
if (rankIdx > myRankIdx) {
continue;
}
ranks[rankIdentifier] = Object.values(rankNames)[rankIdx];
ranks[rankIdentifier] = rankNames.values()[rankIdx];
}
if (isLoggedIn) {

View file

@ -1,32 +1,5 @@
'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);
const isEnumerable = Function.bind.call(
Function.call, Object.prototype.propertyIsEnumerable);
if (!Object.values) {
Object.values = function values(O) {
return reduce(keys(O), (v, k) => concat(
v, typeof k === 'string' && isEnumerable(O, k) ?
[O[k]] :
[]), []);
};
}
if (!Object.entries) {
Object.entries = function entries(O) {
return reduce(
keys(O), (e, k) =>
concat(e, typeof k === 'string' && isEnumerable(O, k) ?
[[k, O[k]]] :
[]), []);
};
}
// fix iterating over NodeList in Chrome and Opera
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
@ -39,6 +12,7 @@ Node.prototype.prependChild = function(child) {
}
};
// non standard
Promise.prototype.always = function(onResolveOrReject) {
return this.then(
onResolveOrReject,
@ -48,6 +22,7 @@ Promise.prototype.always = function(onResolveOrReject) {
});
};
// non standard
if (!String.prototype.format) {
String.prototype.format = function() {
let str = this.toString();
@ -66,6 +41,7 @@ if (!String.prototype.format) {
};
}
// non standard
Number.prototype.between = function(a, b, inclusive) {
const min = Math.min(a, b);
const max = Math.max(a, b);