繁体   English   中英

Babel 模块解析器无法按预期工作

[英]Babel module resolver doesn't work as expected

我在我的节点项目中使用 eslint 配置了 babel-plugin-module-resolver。 这是我的 eslintrc。

{
  "env": {
    "es6": true,
    "node": true
  },
  "extends": [
    "airbnb-base"
  ],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "settings": {
    "import/resolver": {
      "babel-module": {}
    }
  },
  "rules": {
    "class-methods-use-this": "off",
    "newline-per-chained-call": "off",
    "indent": ["warn", 2],
    "quotes": ["warn", "single"],
    "no-unused-vars": ["error", {"warn": "none"}],
    "max-len": ["warn", 150],
    "no-console": 1,
    "object-curly-newline": ["warn", {
      "ObjectPattern": { "multiline": true },
      "ExportDeclaration": { "multiline": true, "minProperties": 4 }
    }]
  }
}

这是我的 babelrc 文件。

{   
  "presets": ["@babel/preset-env"],
  "plugins": [
    [
      "module-resolver",
      {
        "alias": {
          "constants": "./constants",
          "database": "./database",
          "library": "./library",
          "mappers": "./mappers",
          "middleware": "./middleware",
          "models": "./models",
          "repositories": "./repositories",
          "routes": "./routes",
          "services": "./services",
          "utils": "./utils"
        }
      }
    ]
  ] 
} 

现在在我的项目中,路径像这样正常工作。

import User from 'models/user.model';
import UserRepository from 'repositories/user.repository';

但我有以下问题。 当我单击导入时,它不会 go 到定义。 IntelliSense 不工作。

我在这里用这些插件做什么? 我希望没有智能感知和 go 来定义(导航)功能。

@shashika, you have to set up the jsconfig.json for the javascript project, tsconfig.json for the typescript project to make your custom-defined path go to the respective files definition,

例子:

    {
     "compilerOptions": {
       "baseUrl": ".",
       "paths": {
         "@/*": ["./src/*"],
         "@util/*": ["./util/*"],
       },
    }
  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM