简体   繁体   English

如何使用Gulp将多个打字稿文件编译成一个javascript文件?

[英]How to compile multiple typescript files into one javascript file with Gulp?

I have multiple typescript files I want to compile into one single javascript file. 我有多个打字稿文件,我想编译成一个单独的javascript文件。 I have the following code so far: 到目前为止,我有以下代码:

var typescript = require('gulp-typescript');
gulp.task('typescript', function () {
  gulp.src('wwwroot/app/**/*.ts')
    .pipe(typescript({
      out: 'script.js'
    }))
    .pipe(sourcemaps.init())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('wwwroot/app'))      
});

I have searched online on how this is done but couldn't seem to find anything useful. 我已经在线搜索了这是如何完成的,但似乎找不到任何有用的东西。 I read that the 'out' option would concatenate and produce output to a single file. 我读到'out'选项将连接并生成输出到单个文件。 Can anyone point me to the right direction? 有人能指出我正确的方向吗? So far the code I have would only create one javascript for every typescript file I have. 到目前为止,我所拥有的代码只会为我拥有的每个打字稿文件创建一个javascript。

Davin is right. 达文是对的。

From the gulp-typescript docs: 来自gulp-typescript文档:

"Concatenate files “连接文件

The tsc command has the ability to concatenate using the --out parameter. tsc命令能够使用--out参数进行连接。 gulp-typescript doesn't have that, because you should use the gulp-concat plugin for that, or - if you want sourcemaps - gulp-concat-sourcemaps. gulp-typescript没有这个,因为你应该使用gulp-concat插件,或者 - 如果你想要sourcemaps - gulp-concat-sourcemaps。

The tsc command sorts the files using the tags. tsc命令使用标记对文件进行排序。 gulp-typescript does this when you enable the sortOutput option. 启用sortOutput选项时,gulp-typescript会执行此操作。 You can use the referencedFrom filter to only include files that are referenced from certain files." 您可以使用referencedFrom过滤器仅包含从某些文件引用的文件。“

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM