我正在使用节点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文件保留在node中,而不是混合在vue中,但是要使build vue(在公共文件夹内部)也能够读取
理想情况下,我想从vue-project中读取config.js,当我做npm run build
时,我也可以从public(我在其中放置构建的vue项目的地方)读取config.js
这是我失败的,过于复杂的尝试
由于您放置在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会缓存值吗?
请咨询。我希望我的榜样可以帮助您理解我的想法。随时问我可以帮助您澄清的任何事情
谢谢