V
V
Vladimir Golub2021-05-21 15:48:32
JavaScript
Vladimir Golub, 2021-05-21 15:48:32

How to set windows and phpstrom to work with paths like '@/...'?

In a nuxt project, I use the following paths to import components:

components: {
      ContainerElement: () => import("@/components/grid/ContainerElement"),


On Mac, there are no problems navigating through them, how to fix this problem on windows?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim, 2021-05-21
@RazerVG

Create jsconfig and/or tsconfig file with aliases

// jsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/common/*": [
        "../src/common/*"
      ],
      "@/components/*": [
        "../src/common/components/*"
      ],
      "@/utils/*": [
        "../src/common/utils/*"
      ],
      "@/modules/*": [
        "../src/modules/*"
      ]
    }
  }
}

and something like this
/ tsconfig.json
{
  "extends": "../tsconfig.json",
  "include": [
    "./**/*.ts*"
  ],
  "exclude": [],
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/common/*": [
        "../src/common/*"
      ],
      "@/components/*": [
        "../src/common/components/*"
      ],
      "@/utils/*": [
        "../src/common/utils/*"
      ],
      "@/modules/*": [
        "../src/modules/*"
      ]
    },
    "types": [
      "cypress"
    ],
    "sourceMap": false,
    "isolatedModules": true
  }
}

UPD:
you can also create a phpStorm.config.js file in the root of the project
in which to write:
System.config({
  "paths": {
    "components/*": "./src/components/*",
    "core/*": "./src/core/*",
    // алиасы и тд
  }
});

upd2:
About config files in a little more detail in the article: https://lmichelin.fr/vscode-intellisense-jsconfig-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question