如何使VSCode读取以编程方式导入的文件

问题描述

当我使用VSCode悬停在导入文件上时,我试图查看它们的文档。

regular/index.js中,如果采用了这种导入方法

module.exports = {
  first: require('./first'),second: require('./second')
}

我会进入app.js

enter image description here

但是如果我在目录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

然后我将看不到文档:

enter image description here

当我使用本地NodeJS代码而不是glob时,没有什么区别。

有什么方法可以以编程方式导入文件,同时无论将文件导入到哪里都能读取其文档?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)