5

We have file structure like

/common
    /src
        /componentA
        /componentB    

And would like to use webpack aliases

resolve: {
  alias: {
    common: 'common/src'
  }
}

to require modules like

require('common/componentA')

Is there any way to teach WebStorm to resolve this to save option by navigation using Ctrl+Click?

ResourceRoot option doesn't help for this case

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Katya Pavlenko
  • 3,303
  • 3
  • 16
  • 28

2 Answers2

2

It's not possible to get webstorm to read your webpack aliases, so you have to have 2 different "config setups" for this. Just means that you have to maintain webpack's alises and also webstorm's resources.

In webstorm just right click a folder and "Mark directory as" > "Resource root".

This is kind of a duplicate of this and there's a better answer here.

Community
  • 1
  • 1
bitten
  • 2,463
  • 2
  • 25
  • 44
  • i have mentioned that resource root solution doesn't work cause i need real alias WITHOUT saving inner folder structure. This question is not a duplication – Katya Pavlenko Dec 20 '16 at 10:36
  • it's kind of a duplicate since in the other answer thread it's kind of explained. although it doesn't mention custom aliases like yours. my use of "kind of" is quite loose.. – bitten Dec 20 '16 at 10:47
  • i did misunderstand the way you were using aliases too, now i understand what you were asking. so sorry about that! although i still think it's not possible. – bitten Dec 20 '16 at 10:48
  • i'm pretty sure it is not possible, but maybe) – Katya Pavlenko Dec 20 '16 at 10:50
  • maybe.. hopefully :3 – bitten Dec 20 '16 at 10:52
  • I just noticed Webstorm already implemented module resolution. https://www.jetbrains.com/help/webstorm/using-webpack.html#webpack_module_resolution – Oscar Nevarez Aug 01 '20 at 21:04
1

Since Webstorm 2017.2 you can set webpack config file and it will recognize you aliases:

enter image description here

Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166