【问题标题】:concat typescript files in certain order after compilation编译后按一定顺序连接打字稿文件
【发布时间】:2015-11-23 14:57:46
【问题描述】:

我想用 gulp 实现这个:

  1. 将ts编译成js,这个没问题
  2. 然后按照一定的顺序concat js文件,这就是问题

我正在创建 Angular 应用程序,因此我需要按特定顺序连接 ts 文件。

gulp.src(paths.appTs) //src contains files in right order
    .pipe(print())
    .pipe(tsc(tsOptions))
    .pipe(print()) //after compilation are files in bad order
    .pipe(useref())
    .pipe(concant("app.js"))
    .pipe(gulp.dest(paths.dist + "/app"))
    .pipe(print());

最好使用gulp-useref

【问题讨论】:

    标签: javascript typescript gulp concat


    【解决方案1】:

    然后按一定的顺序连接js文件,这就是问题

    我不建议使用out / outFile (https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md),因为手动排序 TS 文件可能是一种痛苦

    强烈推荐使用模块,例如--module commonjs 并利用 webpack 之类的东西为浏览器构建。

    【讨论】:

      【解决方案2】:

      文件的顺序可以通过添加来强制执行

      ///<reference path="relative/path/to/file.ts" />
      

      在您的 .ts 文件的顶部。

      更多信息,请参阅

      https://www.typescriptlang.org/docs/handbook/namespaces.html#splitting-across-files

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-17
        • 2016-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-19
        • 1970-01-01
        • 2022-11-15
        相关资源
        最近更新 更多