我的问题的快速摘要:
Gulp 3.6.0 dest() 处理 glob-base 的方式与 4.0.0 相同吗?
function other() {
return src([
path.join("src/**/*"),
path.join("!src/**/*.{html,css,js,scss}")
])
.pipe(fileFilter)
.pipe(dest(dist));
}
使用上面的代码运行 Gulp 3.6.0 会产生以下结果:
请注意,通过此代码添加到 dist 文件夹的相关文件夹和文件是:
-app
-assets
-config
favicon.ico
现在在 4.0.0 中运行相同的代码会产生以下结果:
我知道 glob-base 在通过管道传输时默认添加到目标,但是这种行为与 3.6.0 中 gulp 处理源镜像到目标文件目录结构的方式不同吗?该示例表明并非如此。
如果有人能为我提供一个解决方案来生成与我的 3.6.0 结果中提供的相同的文件夹结构,那就太好了。我尝试过 gulp-flatten 和 gulp-rename 但没有产生仅删除 glob-base 的预期结果。
最佳答案
所以我仍然不确定升级到 Gulp 4.0 对于如何处理 glob-parent/glob-base 的实际意义是什么,但是我设法使用 base 选项获得了我需要的东西。
此选项有效地使路径中/**/之前的附加 src 硬编码路径引用无效。
function other() {
var fileFilter = plugins.filter(function(file) {
return file.stat.isFile();
});
var appFilter = plugins.filter(function(file) {
return file.path.indexOf("\\src\\app\\") === -1;
});
return src(path.join(conf.paths.src, "/**/*"), { base: conf.paths.src })
.pipe(appFilter)
.pipe(fileFilter)
.pipe(dest(conf.paths.dist));
}
关于Node.js Gulp src/dest 4.0 行为与 Gulp 3.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55246635/