我尝试在我的 Nuxt 项目中使用它,但编译失败
在我的插件/sharp.js
import vue from "vue"
import sharp from "sharp"
vue.use(sharp)
我的 nuxt.config.js
plugins: [
'~plugins/sharp.js',
],
编译时我的终端出现错误
Failed to compile with 4 errors friendly-errors 01:16:19
These dependencies were not found: friendly-errors 01:16:19
friendly-errors 01:16:19
* child_process in ./node_modules/detect-libc/lib/detect-libc.js, ./node_modules/sharp/lib/libvips.js friendly-errors 01:16:19
* fs in ./node_modules/detect-libc/lib/detect-libc.js, ./node_modules/sharp/lib/libvips.js friendly-errors 01:16:19
friendly-errors 01:16:19
To install them, you can run: npm install --save child_process fs
最佳答案
sharp是一个 Node.js 包,因此这不适用于 Vue。至少在客户端上下文中不是这样。
您可能最好提前或通过 Cloudinary 等服务优化您的图像。
关于javascript - 在 Nuxt 中使用 Sharp 包的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68340799/