与正常node
您可以设置 JavaScriptNODE_PATH
并需要本地模块。例如给出:
project
node_modules
src
library
index.js
您可以设置NODE_PATH=src
and require("library")
代码库中的任何位置。如何实现同样的效果tsconfig.json
?
我读过模块分辨率页面 https://www.typescriptlang.org/docs/handbook/module-resolution.html,并尝试了以下配置。
{
baseUrl: "src"
}
{
baseUrl: ".",
paths: {
"*": [
"*",
"src/*"
]
}
}
在每种情况下,它都找不到模块src
. I set --allowJs
标志以及当我更改为相对导入时../library
效果很好。
相当于webpack resolve.root http://webpack.github.io/docs/configuration.html#resolve-root.
// webpack.config.js
resolve: {
root: [
path.resolve("./src")
]
}
相当于flow [options] https://flowtype.org/docs/advanced-configuration.html#options.
# .flowconfig
[options]
module.system.node.resolve_dirname=node_modules
module.system.node.resolve_dirname=src
相关问题:
- VSCode 中 TypeScript 文件中的绝对模块路径解析 https://stackoverflow.com/questions/37606571/absolute-module-path-resolution-in-typescript-files-in-vscode/40177442#40177442
- Typescript 模块解析的根路径 https://stackoverflow.com/questions/37535460/root-path-for-typescript-module-resolution
- Typescript 模块解析 https://stackoverflow.com/questions/34766219/typescript-module-resolution
相关问题:
- https://github.com/Microsoft/TypeScript/issues/5239 https://github.com/Microsoft/TypeScript/issues/5239