gulp-typescript编译问题?

时间:2015-11-02 10:12:58

标签: typescript gulp

我有一个gulp任务将ts编译成js。这是代码:

var typescript  = require('gulp-typescript');

gulp.task('scripts', function() {
    return gulp.src([scriptsSrc])
        .pipe(typescript({
            declarationFiles: true,
            noExternalResolve: false,
            sortOutput: true
        }))
        .pipe(concat('script.min.js'))
        .pipe(stripDebug())
        .pipe(uglify())     
        .pipe(gulp.dest('./build/scripts'))
        .pipe(browserSync.reload({stream : true}));
  });

我的main.ts文件:

class Game extends Phaser.Game {   

    constructor() {
        super(800, 600, Phaser.AUTO, 'content',null);
        this.state.add("play", new states.PlayState());
        this.state.start("play");
    }

}

var mygame = new Game();

play.ts:

module states {

    export class PlayState extends Phaser.State {
        create() {
            var text = "Hello!!!";
            var style = { font: "65px Arial", fill: "#ff0000", align: "center" };
            this.game.add.text(0, 0, text, style);
        }
    }   
}

我收到了以下编译错误:

  

src / scripts / main.ts:line 4,col 1,' class'可在ES6中使用(使用   esnext选项)或Mozilla JS扩展(使用moz)。

     

src / scripts / scenes / play.ts:第0行,第0列,'模块'仅限可用   在ES6中(使用esnext选项)。 src / scripts / scenes / play.ts:第1行,第15行,预期'来自'而是看到' {'。 SRC /脚本/场景/ play.ts:   第3行,第5栏,预期'(字符串)'而是看到了“出口”#。   src / scripts / scenes / play.ts:第3行,第11行,缺少分号。   src / scripts / scenes / play.ts:line 3,col 12,' class'可用   ES6(使用esnext选项)或Mozilla JS扩展(使用moz)。   src / scripts / scenes / play.ts:第9行,第1列,不可恢复的语法错误。   (81%扫描)。

我的编译文件可以在Safari和Google Chrome中运行,没有任何问题。但是如何处理错误信息呢?我的tsp版本是1.6.2。

1 个答案:

答案 0 :(得分:0)

设置esnext选项并按照注释中的建议使用命名空间应该可以解决问题。你能否确认一下有效?

相关问题