【问题标题】:Destination folder is empty, imagemin webp is not working目标文件夹为空,imagemin webp 不工作
【发布时间】:2020-05-09 18:08:21
【问题描述】:
imagemin([__dirname + 'images/raw/*.{jpg,png}'], {
    destination: __dirname + '/images/converted/',
    plugins: [
      imageminWebp({
        quality: 75,
        resize: {
          width: 1000,
          height: 0
        }
      })
    ]
  })
  .then(() => {
    console.log('Images optimized');
  })

代码运行良好,我收到“图像优化”消息,但目标文件夹为空。代码没有发生任何事情。有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: node.js image-compression webp sharp


    【解决方案1】:

    问题在于您的输入路径。 __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}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-18
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 1970-01-01
      • 2017-12-13
      • 2015-04-17
      • 1970-01-01
      相关资源
      最近更新 更多