如何仅在服务器端使用nuxtjs插件?

时间:2018-10-22 12:28:36

标签: nuxt.js hexo

我有一个插件,可以插入一些要存储的变量。但这是一个节点模块,并调用一些nodejs特殊API。

我在官方文档中找到了一个配置

ssr: Boolean (default to true) If false, the file will be included only on the client-side.

但是它仅用于客户端

这是我的插件代码

var Hexo = require("hexo")

export default ({app, store}) => {
  var hexo = new Hexo(process.cwd() + '/hexo',{})

  hexo.load().then(function(){
  var posts = hexo.locals.get("posts")
  var pages = hexo.locals.get("pages")
  var categories = hexo.locals.get("categories")
  var tags = hexo.locals.get("tags")
  store.$commit("init",[posts,pages,categories,tags])
})
}

我跑步时

npm run dev

控制台显示

These dependencies were not found:

* child_process in ./node_modules/hexo-util/node_modules/cross-spawn/index.js
* fs in ./node_modules/graceful-fs/graceful-fs.js, ./node_modules/graceful-fs/fs.js and 19 others
* module in ./node_modules/hexo/lib/hexo/index.js

我尝试安装这些模块,但是在它们的modules文件夹中,只有package.json 没有* .js文件

相同的问题没有正确的答案。

Plugin only server side

0 个答案:

没有答案