簡體   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