使用gulp复制文件夹及其内容

3
我有一个文件夹叫做node_modules,其中包含@bower_components文件夹、jquery-powertip文件夹以及其他文件夹。
使用gulp任务,我想将@bower_components文件夹和jquery-powertip文件夹及其内容复制到目标文件夹中。
我遇到的问题是如何复制jquery-powertip文件夹及其内容。
我尝试了以下方法:
gulp.task('move-dependencies', function () {
    return gulp.src(['node_modules/@bower_components/**', 'node_modules/jquery-powertip'])
               .pipe( gulp.dest(src + '/bower_components') );
});

但这只会复制 jquery-powertip 文件夹而不包括其内容。
我也尝试了这个:
gulp.task('move-dependencies', function () {
    return gulp.src(['node_modules/@bower_components/**', 'node_modules/jquery-powertip/**'])
               .pipe( gulp.dest(src + '/bower_components') );
});

但这将复制 jquery-powertip 文件夹的内容到目标文件夹中(我没有在目标文件夹中得到 "jquery-powertip" 文件夹,只有它的内容)。

那么我该如何解决这个问题?

2个回答

4
我会这样做:

gulp.task('move-dependencies', function () {
    var task1 = gulp.src(['node_modules/@bower_components/**'])
                .pipe( gulp.dest(src + '/bower_components') );
    var task2 = gulp.src(['node_modules/jquery-powertip/**'])
                .pipe( gulp.dest(src + '/bower_components/jquery-powertip') );
    return [ task1, task2 ]; // or merge(task1, task2);
});

抱歉,但这个程序没有运行成功,它抛出了某种异常,我无法看到它,因为我正在使用“frontend-maven-plugin”来运行gulp任务。 - Renaud is Not Bill Gates
你能创建一个类似于move-dependencies-2的单独任务吗? - Taha Paksu
没关系,我使用了合并插件,而不是返回数组或两个任务,我这样做:return merge(task1, task2)。感谢你的帮助。 - Renaud is Not Bill Gates
不用谢。我会修复它以供参考。 - Taha Paksu

0

以防有人重新遇到这个问题。在要保留的文件夹名称前加上星号对我有用(https://github.com/gulpjs/gulp/issues/1358#issuecomment-563448694)。

// will copy the assets folder and its sub directories + files to the destination
return gulp.src('assets*/**/*')

// will only copy the sub directories + files of the assets folder to the destination
return gulp.src('assets/**/*')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接