Search code examples
javascripttypescriptgulp

How to copy files that do not need to be compiled in Gulp?


Suppose that my project is like this:

├── dist
├── src
│   ├── greeter.ts
│   ├── index.html
│   └── test.txt
└── tsconfig.json

Only greeter.ts need to be complied to dir dist, but how about other files? How to copy other files to dir dist?

here is my gulpfile.js:

gulp.task('ts',cb=>{
    return gulp.src('src/**/*.ts')
        .pipe(sourcemaps.init())
        .pipe(tsProject())
        .js
        .pipe(babel({
            presets: ['env']
        }))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('dist'));
});

Solution

  • Create a another task to copy other files and add its dependency on other task

    gulp.task('copyFile', function () {
        return gulp.src([
            'src/**/*', //Include All files
            '!src/**/*.ts' //It will exclude typescript files           
        ]).pipe(gulp.dest('dist'));
    });
    
    gulp.task('ts', ['copyFile'], cb => {
        //Your existing code
    });