在 Vue Nuxt 中观察并重新加载 api 文件夹 [英] Watch and reload api folder in Vue Nuxt

查看:87
本文介绍了在 Vue Nuxt 中观察并重新加载 api 文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让 nuxt 监视非标准"目录并重新编译/重新加载自身,更具体地说是针对具有附加服务器 api 的目录?

How to make nuxt watch for "non standard" directories and recompile / reload itself, and more specifically for dirs with additional server apis?

我在 ~/api/ 中有我的 express api.由于我使用 '~/api' 引用了 serverMiddleware 中的目录,所以当我对该目录中的文件进行一些更改时,我希望 Nuxt 重新加载,但它没有.

I have my express api in ~/api/. Since I reference the directory in serverMiddleware with '~/api', I would expect Nuxt to reload when I make some changes to the files in that dir, but it doesn't.

我只是使用 npm run dev 来触发 nuxt,我对 nodemon(如果它在内部使用)或 webpack 没有任何直接控制权(我很确定是).我尝试添加 watch: [ '~/api/*.js'], watch: [ '~/api/index.js'], watch:[ '~/api/**/*.js']nuxt.conf.js 中构建但没有运气.

I'm simply using npm run dev that fires nuxt, I don't have any direct control on either nodemon (if it's used internally) or on webpack (that I'm pretty sure is). I tried adding watch: [ '~/api/*.js'], watch: [ '~/api/index.js'], watch: [ '~/api/**/*.js'] to build in nuxt.conf.js but with no luck.

推荐答案

只需使用 watch: ['api/**/*.js']watch: ['api'].

与文档显示的 build.watch 中的自定义路径相反,没有通过 Nuxt.resolveAlias() 规范化,这意味着 Nuxt 前缀像 ~@ 不会被实际路径替换.
更进一步,当观察者通过 chokidar 创建时,检查的路径仍然是~/api"(不存在).

Contrary to what the docs show custom paths in build.watch are not normalized via Nuxt.resolveAlias(), which means that Nuxt prefixes like ~ and @ are not replaced by the actual paths.
Further down the line, when the watchers get created via chokidar, the checked path will still be "~/api" (which doesn't exist).

错误报告:https://github.com/nuxt/nuxt.js/问题/2983

这篇关于在 Vue Nuxt 中观察并重新加载 api 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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