Rajind Ruparathna Rajind Ruparathna - 1 month ago 18
TypeScript Question

gulp - how can I exclude a file which is referenced in other added files?

I am trying to exclude this app/custom.ts file from gulp concatenated file. However I noticed that since custom.ts file is referenced in one of other files, custom.ts file is not excluded even though I try to exclude it.

Is it the normal behaviour ? Or am I doing something wrong here ?

How can I exclude this file or use it in a separate bundle ?

gulp.task('app-bundle', function () {
var tsProject = ts.createProject('tsconfig.json', {
typescript: require('typescript'),
outFile: 'app.js'
});

var tsResult = gulp.src([
'!app/custom.ts',
'app/**/*.ts'
]).pipe(ts(tsProject));

return tsResult.js.pipe(addsrc.append('config-prod.js'))
.pipe(concat('app.min.js'))
.pipe(gulp.dest('.'));
});

Answer

You can use gulp-ignore https://www.npmjs.com/package/gulp-ignore to ignore a particular file from the pipeline. As per the example provided in the sample add

.pipe(gulpIgnore.exclude(condition))

before

.pipe(addsrc.append('config-prod.js'))

of your code.