Github 项目仓库:https://github.com/Fralleee/lerna-intellisense-jsdoc-vscode https://github.com/Fralleee/lerna-intellisense-jsdoc-vscode
我有一个包含两个包(Web 和 API)的 monorepo 项目。这些是使用 Lerna 连接的。 Web项目导入API包,并使用JSDoc记录API请求。
The documentation gets loaded perfectly if the API package is released and imported from NPM.
However, if it is run locally via Lerna & Webpack dev server, the documentation is lost and only available in the local code (in the API folder).
我尝试过使用模块和命名空间编写文档并搜索不同类型的解决方案,但似乎都不起作用。
JSDoc 和函数:
/**
* Get comments from JSON placeholder API
* @namespace API
* @module
* @param {GetCommentsRequestExample} input PostId
* @returns {Promise.<GetCommentsResponseExample>} Array of comments
*/
export const getComments = input => apiGet('https://jsonplaceholder.typicode.com/comments', input, GetCommentsRequest, GetCommentsResponse)
我不明白为什么 JSDoc 在包发布时有效,但在本地运行时无效。
经过 2 小时的额外测试后编辑
我使用 API 包中的索引文件导出所有内容。该索引文件从包中导入所有内容,然后将其像单个入口点一样传送。
如果我直接在此索引文件中定义函数和 JSDoc,则 JSDoc 可用于其他包,即使在本地运行时也是如此。
所以这似乎是导出 -> 导入 -> 再次导出的问题,弄乱了 JSDoc。这不是一个解决方案,因为 Api 包的代码太多,无法放入单个文件中。