如何使IntelliJ IDEA解析webpack需要在node_modules目录之外? [英] How to make IntelliJ IDEA resolve webpack requires out of node_modules directory?

查看:822
本文介绍了如何使IntelliJ IDEA解析webpack需要在node_modules目录之外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IntelliJ无法解析使用webpack要求调用的javascript模块,这些模块不在 node_modules 目录中

IntelliJ cannot resolve javascript modules called with webpack requires which are not inside the node_modules directory

想象一下这个项目结构:

Imagine this project structure:

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

这是我的webpack配置

This is my webpack config

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

这就是我使用webpack的要求

And this is how I use webpack's require

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

所以这在我的应用程序中完美运行,而IntelliJ看起来很满意' react / addons',如何理解导航,代码完成和'components / one'和'util / tool'的文档查找?

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'?

我是到目前为止尝试了:

I've tried so far:

但是没有运气到目前为止。谢谢。

But no luck so far. Thanks.

推荐答案

我认为这应该有用(或者无论如何都是这样)。

I think this should work (or so it did in my case anyway).

在IntelliJ中:

In IntelliJ:


  1. 打开项目

  2. 文件> 项目结构

  3. 在左侧,选择模块

  4. 从目录结构中,选择源所在的文件夹( util src )并将其标记为资源

  5. 点击申请

  1. Open the project
  2. File > Project Structure
  3. On the left hand side, select Modules
  4. From your directory structure, select the folders where your sources are (util and src) and mark them as Resources
  5. Click Apply

您现在应该可以完成代码和文档。

You should have code completion and documentation available now.

这篇关于如何使IntelliJ IDEA解析webpack需要在node_modules目录之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆