我为路径添加打字稿配置:
{
//.....
"moduleResolution": "node",
{
"baseUrl": "app",
"paths": {
"@app/*": ["*"],
"@folder/*": ["folder/*"],
//Other paths
},
Run Code Online (Sandbox Code Playgroud)
}
为 webpack 添加配置:
resolve: {
extensions: [".tsx", ".ts", ".js", ".jsx", ".css", ".json"],
alias: {
"@app":path.resolve(__dirname + "../", "app"),
"@services":path.resolve(__dirname + "../app", "folder")
},
modules: [
"node_modules", path.resolve(process.cwd(), "app")
],
plugins: [
new TsConfigPathsPlugin({
configFile: "../tsconfig.json"
}),
],
},
Run Code Online (Sandbox Code Playgroud)
这是我的 .eslint 文件:
"settings": {
"import/resolver": {
"node": {
"paths": [
"app"
],
"extensions": [
".ts",
".tsx",
".jest.tsx",
".d.ts"
]
}
}
Run Code Online (Sandbox Code Playgroud)
之后我尝试导入这样的东西:
import …
Run Code Online (Sandbox Code Playgroud)