tsconfig.json 内 paths 的配置如下:
"compilerOptions": { "target": "es5", "module": "commonjs", "baseUrl": ".", "paths": { "services/*": ["app/services/*"] } }
编译前:
编译后:
这样会报错:can not fond module xxx
尝试使用了module-alias
、@momothepug/tsmodule-alias
等插件都无效,原因是因为使用了 import x from 'x'
语法。 但我仍然想用 import 语法来引用模块。
1 buhi 2020-06-16 16:40:43 +08:00 ![]() 是的 tsc 不会去转换路径, 需要你自己解决, 如果是 webpack, 就是用 resolve.modules 或者 resolve.alias, 如果是 nodejs, 就是用类似 https://github.com/dividab/tsconfig-paths 的东西 |
![]() | 2 dubenshu 2020-06-17 11:24:20 +08:00 可以考虑使用 babel 来编译 |