我正在使用Typescript和React-Native进行两个程序的项目:
PackageA(叶包装)包含REST客户端和模拟
MyOwnLibrary
- src
-tests
_mocks_
-restClientMock.ts
-restClient.ts
现在,我可以使用“ MyOwnLibrary / lib / tests / _mocks”中的“ import {restClient}”导入内容
但是,我想使用import { restClient } from 'MyOwnLibrary/mocks'
有什么想法可以做到这一点吗?
答案 0 :(得分:0)
使用tsc -init
命令制作tsconfig.json文件
打开文件并编辑baseUrl和路径
"baseUrl": "MyOwnLibrary/src", /* Base directory */
"paths": {
"MyOwnLibrary/mocks" : [ /* Whatever name you want to use */
"tests/_mocks/restClientMock.ts" /* Path to your module */
]
},
然后,您可以像这样简单地导入:
import { restClient } from 'MyOwnLibrary/mocks' /* Imports from MyOwnLibrary/src/tests/_mocks/restClientMock */