【问题标题】:How to copy files that do not need to be compiled in Gulp?如何复制不需要在 Gulp 中编译的文件?
【发布时间】:2017-10-20 12:49:12
【问题描述】:

假设我的项目是这样的:

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

只有greeter.ts需要符合dirdist,但是其他文件呢?如何将其他文件复制到目录dist

这是我的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'));
});

【问题讨论】:

    标签: javascript typescript gulp


    【解决方案1】:

    创建另一个任务来复制其他文件并添加其对其他任务的依赖

    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
    });
    

    【讨论】:

    • 错误:无效的全局参数:./src/**/*,false @Satpal
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 1970-01-01
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多