简体   繁体   English

Webpack中的路径别名,如webpack中的路径别名

[英]Path aliases in WebStorm as in webpack

We have file structure like 我们有像文件结构

/common
    /src
        /componentA
        /componentB    

And would like to use webpack aliases 并且想使用webpack别名

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 ? 有没有办法教WebStorm通过使用Ctrl + Click导航来解决此问题以保存选项?

ResourceRoot option doesn't help for this case ResourceRoot选项对这种情况没有帮助

It's not possible to get webstorm to read your webpack aliases, so you have to have 2 different "config setups" for this. 让webstorm读取你的webpack别名是不可能的,所以你必须有2个不同的“配置设置”。 Just means that you have to maintain webpack's alises and also webstorm's resources. 只是意味着你必须维护webpack的alises和webstorm的资源。

In webstorm just right click a folder and "Mark directory as" > "Resource root". 在webstorm中,只需右键单击文件夹并“将目录标记为”>“资源根”。

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: 从Webstorm 2017.2开始,您可以设置webpack配置文件,它会识别您的别名:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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