简体   繁体   English

如何使IntelliJ IDEA解析webpack需要在node_modules目录之外?

[英]How to make IntelliJ IDEA resolve webpack requires out of node_modules directory?

IntelliJ cannot resolve javascript modules called with webpack requires which are not inside the node_modules directory IntelliJ无法解析使用webpack要求调用的javascript模块,这些模块不在node_modules目录中

Imagine this project structure: 想象一下这个项目结构:

`- project
   |- node_modules
   |  `- react
   |     `- addons.js
   |- webpack.config.js
   |- util
   |  `- tool.js
   `- src
      |- components
      |  `- uno.jsx
      `- two.jsx

This is my webpack config 这是我的webpack配置

// webpack.config.js
var path = require('path'); 
module.exports = {
  resolve: {
    root: [
      path.resolve('./src'),
      path.resolve('./')
    ]
  }
  ...
}

And this is how I use webpack's require 这就是我使用webpack的要求

// two.js
var React = require('react/addons');
var One = require('components/one');
var Tool = require('util/tool');
// dosomething

So this works perfectly within my application, and IntelliJ looks happy with 'react/addons', how to make understand the sources for navigation, code completion and Documentation lookup for 'components/one' and 'util/tool'? 因此,这在我的应用程序中完美运行,IntelliJ看起来很满意'react / addons',如何理解导航,代码完成和'components / one'和'util / tool'的文档查找源代码?

I've tried so far: 我到目前为止尝试过:

But no luck so far. 但到目前为止没有运气。 Thanks. 谢谢。

I think this should work (or so it did in my case anyway). 我认为这应该有用(或者无论如何都是这样)。

In IntelliJ: 在IntelliJ中:

  1. Open the project 打开项目
  2. File > Project Structure File > Project Structure
  3. On the left hand side, select Modules 在左侧,选择Modules
  4. From your directory structure, select the folders where your sources are ( util and src ) and mark them as Resources 从目录结构中,选择源所在的文件夹( utilsrc )并将其标记为Resources
  5. Click Apply 单击“ Apply

You should have code completion and documentation available now. 您应该现在可以使用代码完成和文档。

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

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