目标文件夹为空,imagemin webp无法正常工作

imagemin([__dirname + 'images/raw/*.{jpg,png}'],{
    destination: __dirname + '/images/converted/',plugins: [
      imageminWebp({
        quality: 75,resize: {
          width: 1000,height: 0
        }
      })
    ]
  })
  .then(() => {
    console.log('Images optimized');
  })

代码工作正常,我收到消息“图像优化”,但目标文件夹为空。代码没有任何反应。有人可以帮我这个忙吗?

sasuke1028 回答:目标文件夹为空,imagemin webp无法正常工作

问题出在您的输入路径上。 __dirname会删除斜杠,因此,假设您的工作目录为/Users/user/my-project,则最终会出现如下这样的问题:

/Users/user/my-projectimages/raw/*.{jpg,png}

通常建议通过path.join()加入路径以保持一致性:

const path = require('path');
const inputPath = path.join(__dirname,'images/raw/*.{jpg,png}');
// /Users/user/my-project/images/raw/*.{jpg,png}
本文链接:https://www.f2er.com/2725008.html

大家都在问