我需要将 2 个文件夹的内容复制到另一个文件夹中。如果存在具有相同名称的文件,并且根据文件扩展名,则执行一个函数: - concat : JS, LESS ... - 合并: 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'));
});
Run Code Online (Sandbox Code Playgroud)
有人可以提供任何帮助吗?
编辑:我的基础架构图
|-gulpfile.js
|-bower_components
| |-module
| | |-bower.json
| | |-package.json
| | |-index.less
| | |-hello.png
|-source
| |-bower.json
| |-package.json
| |-index.less
| |-hello.png
Run Code Online (Sandbox Code Playgroud)
这就是我要的 :
|-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)
Run Code Online (Sandbox Code Playgroud)
想要覆盖文件的情况是最简单的,gulp.dest 默认覆盖,而 gulp.src 按顺序处理指定的文件。您希望优先使用源中的文件而不是 Bower_components 中的文件。所以这样的事情应该有效
gulp.task('overwrite', () => {
gulp.src('./bower_components/**/*.png', './source/**/*.png')
.pipe(gulp.dest('./temp'));
});
Run Code Online (Sandbox Code Playgroud)
因此,如果两个位置都存在该文件,则源中的文件将覆盖 ./temp 中的 Bower_components 中的文件。
尝试一下作为开始
| 归档时间: |
|
| 查看次数: |
902 次 |
| 最近记录: |