简体   繁体   English

PhpStorm无法识别Webpack别名

[英]PhpStorm not recognizing webpack alias

My webpack.config.js contains the following part: 我的webpack.config.js包含以下部分:

resolve: {
    extensions: ['*', '.js', '.ts', '.tsx'],
    modules: [
        path.resolve(__dirname, "src"),
        path.resolve(__dirname, "node_modules"),
    ],
    alias: {
        Design: path.resolve(__dirname, "src/Theme/Default")
    }
},

There are 2 folders in this src/Theme folder: Default & Dark . src/Theme文件夹中有2个文件夹: DefaultDark I want to switch it in the alias setting when needed, it's not user controlled. 我想在需要时在别名设置中切换它,它不是用户控制的。

The import I use: 我使用的导入:

import Page from 'Design/Components/Page';

Webpack is working correctly with this but PhpStorm 2018.2 does not recognize this path as correct. Webpack可以正常使用,但是PhpStorm 2018.2无法识别此路径为正确路径。

My PhpStorm settings for webpack are set to the path of my webpack.config.js. 我的webpack的PhpStorm设置被设置为webpack.config.js的路径。

More details and examples / logs can be found here: https://youtrack.jetbrains.com/issue/WI-43146 可在此处找到更多详细信息和示例/日志: https : //youtrack.jetbrains.com/issue/WI-43146

Webpack aliases resolving is not supported when editing TypeScript files, current TypeScript support implementation uses only the TypeScript resolution logic because we need to keep integration with the TypeScript language service (that is not aware of webpack aliases). 编辑TypeScript文件时不支持Webpack别名解析,当前的TypeScript支持实现仅使用TypeScript解析逻辑,因为我们需要保持与TypeScript语言服务的集成(尚不了解Webpack别名)。 You can configure similar mappings in your tsconfig.json file, like: 您可以在tsconfig.json文件中配置类似的映射,例如:

"baseUrl": "",
    "paths": {
      "Design/*": ["src/Theme/Default/*"]
    }

If you miss support for webpack resolving in TypeScript, please vote for WEB-29207 如果您错过在TypeScript中支持Webpack解析的支持,请投票给WEB-29207

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

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