最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to compile multiple typescript files into one javascript file with Gulp? - Stack Overflow

programmeradmin0浏览0评论

I have multiple typescript files I want to pile into one single javascript file. 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. 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.

I have multiple typescript files I want to pile into one single javascript file. 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. 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.

Share Improve this question edited Mar 29, 2018 at 7:39 MSeifert 153k41 gold badges350 silver badges367 bronze badges asked Dec 20, 2014 at 8:14 user2678324user2678324 1
  • 1 You could use gulp-concat after the typescript mand. – Davin Tryon Commented Dec 20, 2014 at 8:23
Add a ment  | 

1 Answer 1

Reset to default 5

Davin is right.

From the gulp-typescript docs:

"Concatenate files

The tsc mand has the ability to concatenate using the --out parameter. gulp-typescript doesn't have that, because you should use the gulp-concat plugin for that, or - if you want sourcemaps - gulp-concat-sourcemaps.

The tsc mand sorts the files using the tags. gulp-typescript does this when you enable the sortOutput option. You can use the referencedFrom filter to only include files that are referenced from certain files."

发布评论

评论列表(0)

  1. 暂无评论