如何使IntelliJ IDEA解析webpack需要在node_modules目录之外? [英] How to make IntelliJ IDEA resolve webpack requires out of node_modules directory?
问题描述
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:
- 在src中添加package.json(npm init)
- 添加src作为设置/语言中的Javascript库遵循此 https://www.jetbrains.com/idea/help/configuring-javascript-libraries的框架.html
- 模仿以下任何与node_modules相关的.idea
但是没有运气到目前为止。谢谢。
But no luck so far. Thanks.
推荐答案
我认为这应该有用(或者无论如何都是这样)。
I think this should work (or so it did in my case anyway).
在IntelliJ中:
In IntelliJ:
- 打开项目
-
文件
>项目结构
- 在左侧,选择
模块
- 从目录结构中,选择源所在的文件夹(
util
和src
)并将其标记为资源 - 点击
申请
- Open the project
File
>Project Structure
- On the left hand side, select
Modules
- From your directory structure, select the folders where your sources are (
util
andsrc
) and mark them as Resources - Click
Apply
您现在应该可以完成代码和文档。
You should have code completion and documentation available now.
这篇关于如何使IntelliJ IDEA解析webpack需要在node_modules目录之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!