node.js - vue如何从node读取js文件
问题描述
我正在使用节点 10.16.0 和 vue 2.6.11,我想在节点根文件夹中有一个 config.js 文件,指向节点结构之外的文件夹
hello
hi.txt
node-project //node project
server.js
config.js
public //contains build vue
vue-project //contains not build vue
config.js 应该包含类似
let txtFile= '../hello/hi.txt';
exports.txtFile = txtFile;
我希望能够将 config.js 文件保留在节点中,而不是混合在 vue 中,但构建 vue(在公共文件夹内)也能够读取它
理想情况下,我想从 vue-project 读取 config.js,当我这样做时npm run build
,我还可以从 public 读取 config.js(我放置构建的 vue 项目的地方)
这是我失败的,过于复杂的尝试
由于您放入 vue 项目的公共文件夹中的所有内容都会传递给构建,并且在构建过程中路径会自动更改,所以我这样做了
hello
hi.txt
node-project //node project
server.js
vue-project //contains not build vue
public
configs
config.js //contains ../../../../hello/hi.txt
src
views
Home.vue //imports configs/config.js
当我这样做时npm run build
,上面变成了
hello
hi.txt
node-project //node project
server.js
public //contains build vue
css
js
fonts
configs
config.js
index.html
于是 config.js 自动转移到了 build vue 中,config.js 的路径自动改变了,config.js 在节点中,方便访问,只有一个子文件夹,没有混入 vue js。
问题是现在 config.js 改变了位置,所以我必须手动将其内容更改为
let txtFile= '../../hello/hi.txt';
我认为它没关系,付出的代价很小,它只是一次手动更改。
但问题是 Vue 没有读取更改后的值。它仍然读取../../../../hello/hi.txt
而不是'../../hello/hi.txt
。重新启动节点没有帮助。我猜vue缓存了这个值?
请指教。我希望我的例子能帮助你理解我想要做什么。随时问我任何可以帮助您澄清的问题
谢谢
解决方案
推荐阅读
- python - 使用 python 的 GCP 数据流。“AttributeError:无法在模块 'dataflow_worker.start' 上获取属性 '_JsonSink'
- jquery - 在 Django 中使用 AJAX 获取 celery 进度
- c# - 无法从传输连接读取数据:现有连接被强行关闭
- python - IOLoop.current().run_in_executor() 和 ThreadPoolExecutor().submit() 的区别
- grails - 在 grails 中使用 saml 插件进行 SSO 后尝试访问 idp url 时出现问题
- python - Python googleapiclient 附加行与背景颜色
- android - 在按钮上,文本和可绘制对象在居中时距离太远
- google-workspace - 无法在 GSuite 中选中“启用 G Suite 域范围委派”
- angular7 - 我们可以为 angular-google-map 应用自定义指令吗
- javascript - 有没有不同的显示图像的方式?