[英]How to configure WebStorm / PhpStorm project so that JS code intelligence works well for Node.js projects?
In WebStorm / PhpStorm / IDEA, there are quite a lot of code intelligence feature for JavaScript built in. However, when developing a Node.js application, including everything from node_modules
complicates matters with things like "Navigate to file" (I don't want the IDE to offer me tens of package.json
s from node_modules
folder, for example). 在WebStorm / PhpStorm / IDEA中,内置了JavaScript的代码智能功能相当多。但是,在开发Node.js应用程序时,包括
node_modules
所有内容node_modules
使“导航到文件”等问题node_modules
复杂(我不知道)希望IDE从node_modules
文件夹中提供数十个package.json
,例如)。 But excluding the node_modules
folder entirely has its own problems - there is no code completion etc. 但是完全排除
node_modules
文件夹有其自身的问题 - 没有代码完成等。
So what's the "right" way to approach this in WebStorm? 那么在WebStorm中解决这个问题的“正确”方法是什么? Should I include only some of the files from
node_modules
? 我应该只包含
node_modules
一些文件吗? Or exclude everything from there and somehow use the concept of project or global libraries? 或者从那里排除所有内容并以某种方式使用项目或全局库的概念?
Thanks. 谢谢。
To do this in the UI (tested from PyCharm 2.7.3, result shown in PhpStorm 6.0.3): 要在UI中执行此操作(从PyCharm 2.7.3测试,结果显示在PhpStorm 6.0.3中):
Add JavaScript Libraries 添加JavaScript库
File → Settings 文件→设置
(Project Settings) → JavaScript → Libraries (项目设置)→JavaScript→库
[Add...] → [添加...]→
Name : node_modules
名称 :
node_modules
Visiblilty : [x] Current project Visiblilty :[x]当前项目
[Attach...] [连接...]
{select project's node_modules folder} {select project的node_modules文件夹}
{repeat for bower } {重复为凉亭 }
Exclude Folder from Project 从项目中排除文件夹
(Project Settings) → Project Structure (项目设置)→项目结构
Right-click on folder → [Excluded] 右键单击文件夹→[排除]
To do this from project's .iml file: 要从项目的.iml文件执行此操作:
Changing the project's .iml
to the following: 将项目的
.iml
更改为以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/bower_components" />
<excludeFolder url="file://$MODULE_DIR$/node_modules" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="node_modules" level="application" />
<orderEntry type="library" name="bower_components" level="application" />
</component>
</module>
Caused the editor to exclude node_modules and bower_components, but make them available for completion and library search 导致编辑器排除node_modules和bower_components,但使它们可用于完成和库搜索
Tested in PyCharm, IntelliJ, and WebStorm. 在PyCharm,IntelliJ和WebStorm中测试过。
这已在WebStorm 7中修复,请参阅http://youtrack.jetbrains.com/issue/WEB-1927 。
Unfortunately there is no easy "right" way. 不幸的是,没有简单的“正确”方式。 You can exclude all node_modules directories that are located inside top level node_modules directory.
您可以排除位于顶级node_modules目录中的所有node_modules目录。 It will make completion better, but not ideal.
这将使完成更好,但不理想。
Further discussion is here: http://devnet.jetbrains.net/message/5468926 . 进一步的讨论在这里: http : //devnet.jetbrains.net/message/5468926 。
您可以下载Node.js集成的插件: http : //plugins.intellij.net/plugin/? webide&pluginId = 6098
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.