我遇到了Google Closure Compiler的问题。我想编译NodeJS代码,但似乎Google CC在require上有一些问题。
一个例子:
'use strict';
var moment = require('moment');
var crypto = require('crypto');
moment.locale('fr');
//TEMP CONFIG
var oddsProb = 0.85;
class Match {
constructor(game, date, t1, p1, t2, p2){
this._isLive = false;
this.t1 = t1;
this.t2 = t2;
this.p1 = p1;
this.p2 = p2;
this.p0 = 100-p1-p2;
this.o1 = (p1==0?0:(oddsProb*100/p1)).toFixed(2);
this.o2 = (p2==0?0:(oddsProb*100/p2)).toFixed(2);
this.o0 = (this.p0==0?0:(oddsProb*100/this.p0)).toFixed(2);
this.date = moment(date);
this.gameType = game;
this.fromNowString = this.date.fromNow();
this._hashCode = crypto.createHash('md5').update(t1+t2+this.date.format("YMMDD")+this.gameType).digest("hex");
//Validation date
if(moment().isBefore(date)){
this._isLive = true;
}
}
serialize(){
return {
_id: this._hashCode.substring(0,24),
date: this.date.valueOf(),
t1: this.t1,
p1: this.p1,
t2: this.t2,
p2: this.p2,
p0: this.p0,
o1: this.o1,
o2: this.o2,
o0: this.o0,
gameType: this.gameType
}
}
static deserialize(s){
return new Match(s.gameType, moment(s.date), s.t1, s.p1, s.t2, s.p2);
}
isLive(){
return this._isLive;
}
}
module.exports = Match;
在其他文件中:
var Match = require('./match');
Google CC给了我这个错误:ERROR - Variable Match first declared in /src/public/routes.js
我的gulpfile:
var gulp = require('gulp');
var source = './src'; // dossier de travail
var destination = './dist'; // dossier à livrer
var closureCompiler = require('google-closure-compiler').gulp();
gulp.task('js-compile', function () {
return gulp.src(source+'/**/*.js', {base: source})
.pipe(closureCompiler({
compilation_level: 'SIMPLE',
warning_level: 'VERBOSE',
js_output_file: 'output.min.js'
}))
.pipe(gulp.dest(destination));
});
有什么想法吗?谢谢!