18

In Vue.js you have the possibility to use the @ in a path file as a shortcut to your src folder. It is nice because all your files have an absolute path.

However I don't manage to find a way to configure WebStorm to understand that and allow me to follow and check if the file exist when using it.

Example :

import Business from '@/components/Business/Business'

Writing that I want WebStorm to tell me if the file does not exists and to allow me to go to that file directly.

I did not manage to find any answer about it and neither managed to find a way to do it in the IDE.

2
  • 4
    Check this thread: intellij-support.jetbrains.com/hc/en-us/community/posts/… Commented Jul 30, 2018 at 8:16
  • What worked for me (don't use vue-cli) : 1) Set the config webpack file in the IDE in the settings & 2) For .vue files I can import components without .vue extension in the path, but for js files I still need to add .vue to make him understand it. But that's fine ;) Commented Jul 31, 2018 at 5:38

4 Answers 4

51

For vue-cli3, you need to specify a full path to node_modules/@vue/cli-service/webpack.config.js as a webpack configuration file in Settings | Languages & Frameworks | JavaScript | Webpack.

Note that this only works for JavaScript; webpack aliases are not resolved when using components written in TypeScript, path mappings in tsconfig.json should be used instead

Sign up to request clarification or add additional context in comments.

6 Comments

Actually I did not use vue-cli but I needed to define my webpack configuration file anyway to make intelliJ understand what my @ means while coding as it worked when bundling! Thanks a lot !
Another reference for this answer: youtrack.jetbrains.com/issue/…
WEB-32564 was fixed in 2018.2.3
this relative path doesn't seem to work for me - it only works if I put the full absolute path: /Users/..etc../MyProject/node_modules/@vue/cli-service/webpack.config.js. Any idea on how to import it using the project relative path?
My Vue project is in a subfolder called client, so in order to make it work I had to use the following: $PROJECT_DIR$/client/node_modules/@vue/cli-service/webpack.config.js in Settings | Languages & Frameworks | JavaScript | Webpack. Worked like a charm. Thanks @lena!!
|
7

In phpstorm 2020.3.3, I could fix this by

  • Opening Settings > Languages & Frameworks > JavaScript > Webpack and choose "Automatically"
  • Once saved, this opens a popup asking to run webpack configuration. Click "Trust project and run"
  • Fixed!

Comments

4

Webstorm already supports resolving alias. Webstorm read your webpack.config.js in background.

If you're using vue-cli 3, we don't have webpack.config.js, but you can create webpack.config.js file manually

module.exports = {
  resolve: {
    alias: {
      "@": require("path").resolve(__dirname, "src") // change this to your folder path
    }
  }
};

webstorm will resolve it automatically

1 Comment

Thanks for your answer but actually webpack manage to find my files, I already have such a configuration for it. My problem is just when coding in webstorm it does manage to find it and highlight an error and of course does not allow to do a ctrl + click to reach the file and open it directly :(
4

vue-cli3 you can select node_modules/@vue/cli-service/webpack.config.js as webstorm configuration file Settings > Languages & Frameworks > JavaScript > Webpack. or create webpack.config.js in the root directory, content is

const resolve = dir => require('path').join(__dirname, dir);

module.exports = {
    resolve: {
        alias: {
            '@': resolve('src')
        }
    }
};

And then as webstorm configuration file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.