使用Gulp.Dest()时如何省略所有子目录?

发布于 2025-01-27 11:28:27 字数 352 浏览 2 评论 0原文

我在Gulp中有一项任务:

// converts jpg/png images to webp
function webpImage() {
    return src('src/**/*.{jpg,png}')
        .pipe(imagewebp())
        .pipe(dest('dist/images'));
}

我想要的就是将所有新的.webp图像直接放入DIST/图像中。我不想要任何子文件夹,类似的路径:dist/images/header/header.jpg。我需要这样的:/dist/images/header.jpg

我尝试使用src()的基本选项做点事位于图像。

I've got a task in Gulp:

// converts jpg/png images to webp
function webpImage() {
    return src('src/**/*.{jpg,png}')
        .pipe(imagewebp())
        .pipe(dest('dist/images'));
}

All I want is to put all the new .webp images directly into dist/images. I don't want any sub folders, paths like this: dist/images/header/header.jpg. I need it to be like this: /dist/images/header.jpg

I've tried to do something with the base option of src() and it didn't work out because I don't know how to get full path of located image.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心激荡 2025-02-03 11:28:27

查看 gulp-flatten 软件包。我已经有一段时间没有使用过,因此请确保它与Gulp V4一起使用。它“使”文件的目录结构“变平”,以消除所需的尽可能多的父目录。

// other requires
var flatten = require('gulp-flatten');

function webpImage() {
    return src('src/**/*.{jpg,png}')
        .pipe(imagewebp())
        .pipe(flatten())
        .pipe(dest('dist/images'));
}

Look at the gulp-flatten package. I haven't used it for a while so make sure it works with gulp v4. It "flattens" the directory structure of the files passing through to eliminate as many parent directories as you need.

// other requires
var flatten = require('gulp-flatten');

function webpImage() {
    return src('src/**/*.{jpg,png}')
        .pipe(imagewebp())
        .pipe(flatten())
        .pipe(dest('dist/images'));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文