在 Nuxt 中使用sharp包的问题 [英] issue using sharp package in Nuxt

查看:32
本文介绍了在 Nuxt 中使用sharp包的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的 Nuxt 项目中使用它,但编译失败

i tried using this in my Nuxt project, but it failed upon compiling

在我的插件/sharp.js

in my plugin/sharp.js

import vue from "vue"
import sharp from "sharp"
vue.use(sharp)

还有我的 nuxt.config.js

and i my 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 是一个节点.js 包,因此这不适用于 Vue.至少,不是在客户端上下文中.

sharp is a Node.js package, hence this will not work with Vue. At least, not in the client context.

您可能最好提前或通过 Cloudinary 之类的服务优化您的图像.

You are probably better optimizing your images ahead of time or via a service like Cloudinary.

这篇关于在 Nuxt 中使用sharp包的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆