在monorepo设置中,通过软件包导出所有内容之间是否存在差异。
exports
vs.
index.ts
事物都完全不同。
// package.json
{
"exports": {
"./theme": "./src/theme.ts"
},
}
导入主题,而使用
// src/index.ts
export { theme } from './theme.js
your-project/theme
或
index.js
或your-project
。
通过提供一个root
your-project/index.js
wihtout and the the the的定义,您将项目结构盖开。其他项目可以从中导入任何内容,例如index.js
exports
中,您可以明确定义入口点并自动禁止导入任何其他文件。
我通常的方法正在结合这两种技术。我有一个定义公共入口点,甚至为其编写单元测试,以确保它导出所有必需的东西,而没有其他内容。然后在
package.json
中使用
your-project/src/internal/utils.js
来确保使用我的模块的唯一方法是与
exports
。