【问题标题】:gulp-typescript compilation issues?gulp-typescript 编译问题?
【发布时间】:2015-11-02 10:12:57
【问题描述】:

我有一个 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:第 4 行,第 1 列,'class' 在 ES6 中可用(使用 esnext 选项)或 Mozilla JS 扩展(使用 moz)。

src/scripts/scenes/play.ts: line 0, col 0, 'module' 仅可用 在 ES6 中(使用 esnext 选项)。 src/scripts/scenes/play.ts:第 1 行,第 15 列,预期为“来自”,而是看到“{”。 src/scripts/scenes/play.ts: 第 3 行,第 5 列,应为“(字符串)”,而是看到“导出”。 src/scripts/scenes/play.ts:第 3 行,第 11 列,缺少分号。 src/scripts/scenes/play.ts:第 3 行,第 12 列,“类”在 ES6(使用 esnext 选项)或 Mozilla JS 扩展(使用 moz)。 src/scripts/scenes/play.ts:第 9 行,第 1 列,不可恢复的语法错误。 (81% 已扫描)。

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

【问题讨论】:

标签: typescript gulp


【解决方案1】:

按照 cmets 中的建议设置 esnext 选项并使用命名空间应该可以解决问题。你能确认这是有效的吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多