Reputation: 1212
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.
Upvotes: 18
Views: 12926
Reputation: 93
In phpstorm 2020.3.3, I could fix this by
Upvotes: 7
Reputation: 93748
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
Upvotes: 51
Reputation: 41
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.
Upvotes: 4
Reputation: 22403
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
Upvotes: 4