M
M
Maxim2021-04-16 09:38:56
webpack
Maxim, 2021-04-16 09:38:56

How to add context hints for a module with a "module" path in VS Code?

Webpack understands absolute, relative and "modular" paths. For example:
'../../scripts/script.ts' - relative
'H:/first-task/src/scripts/script.ts' - absolute
'scripts/script' - modular.
With the help of the resolver and the modules, extensions setting, webpack can find modules along the module path.
And VS Code can't.
Therefore, for absolute and relative paths, it gives hints (about what exactly is imported, which fields, functions, etc.), but not for modular ones.

Is there a way to teach VS Code to understand such paths for issuing contextual hints?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2021-04-16
@voxman90

If I understood everything correctly, then you need to place the jsconfig.json file in the root of the project, (see https://code.visualstudio.com/docs/languages/jsconfig ) in which you write something like:

spoiler

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
// пример других алиасов (копия webpack aliases):
      "src/*": [
        "src/*"
      ],
      "scripts/*": [
        "scripts/*"
      ],
      "app/*": [
        "*"
      ],
      "components/*": [
        "src/components/*"
      ],
      "layouts/*": [
        "src/layouts/*"
      ],
      "pages/*": [
        "src/pages/*"
      ],
      "assets/*": [
        "src/assets/*"
      ],
      "boot/*": [
        "src/boot/*"
      ]
    }
  },
  "exclude": [
    "dist",
    "node_modules",
//... другие не нужные пути
  ]
}


then inside VS code anything like "path intellisense" and "peek definition" will work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question