简体   繁体   中英

Path aliases in WebStorm as in webpack

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

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 .

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

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM