我需要在另一个文件夹中复制两个文件夹的内容。如果有同名的文件,并且取决于文件扩展名,将执行一个函数:- concat : JS,LESS .- merge : json - overwrite : images,HTML .
要复制这两个文件夹不是问题,这是第二部分:(
var route = 'bower_components/any-folder';
gulp.task('test', function() {
return gulp.src([route + '**/*', 'source/**/*', route + '!bower_components{,/**}', route + '!node_modules{,/**}'])
.pipe( $.replace( '@@_APP_@@', 'myApp' ) )
.pipe(gulp.dest('./temp'));
});有人能提供任何帮助吗?
编辑:我的基础架构图
|-gulpfile.js
|-bower_components
| |-module
| | |-bower.json
| | |-package.json
| | |-index.less
| | |-hello.png
|-source
| |-bower.json
| |-package.json
| |-index.less
| |-hello.png这就是我想要的:
|-public
| |-bower.json (merge between bower_components/module & source)
| |-package.json (merge between bower_components/module & source)
| |-index.less (concat between bower_components/module & source)
| |-hello.png (provide from source, overwrite the copy from bower_components/module)发布于 2016-08-12 11:43:41
您想要覆盖文件的情况是最简单的,因为默认情况下是gulp.dest覆盖,而gulp.src按顺序处理指定的文件。您希望源文件优先于bower_components中的文件。所以像这样的事情应该能起作用
gulp.task('overwrite', () => {
gulp.src('./bower_components/**/*.png', './source/**/*.png')
.pipe(gulp.dest('./temp'));
});因此,如果文件同时存在于两个位置,那么源中的文件将覆盖./temp中的bower_components文件。
试着开始吧
https://stackoverflow.com/questions/38901565
复制相似问题