问题描述
当我使用VSCode悬停在导入文件上时,我试图查看它们的文档。
在regular/index.js
中,如果采用了这种导入方法:
module.exports = {
first: require('./first'),second: require('./second')
}
但是如果我在目录programmatic
中有很多文件,并且想使用glob
以编程方式导入它们:
const glob = require('glob')
const path = require('path')
let methods = {}
glob.sync('./programmatic/*.js').forEach(file => {
const method = file.split('.js')[0].split('programmatic/')[1]
if (method !== 'index') methods[method] = require(path.resolve(file))
})
module.exports = methods
当我使用本地NodeJS代码而不是glob
时,没有什么区别。
有什么方法可以以编程方式导入文件,同时无论将文件导入到哪里都能读取其文档?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)