在 Vue Nuxt 中观察并重新加载 api 文件夹 [英] Watch and reload api folder in Vue Nuxt
问题描述
如何让 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屋!