简体   繁体   English

如何将现有的node.js模块导入Intellij IDEA?

[英]How to import existing node.js module into Intellij IDEA?

I have an existing Node.js codebase, forked from GitHub. 我有一个现有的Node.js代码库,从GitHub分叉。 Now I want to import it to the Intellij IDEA 13 (ultimate version, which supports Node.js). 现在我想将它导入到Intellij IDEA 13(最终版本,它支持Node.js)。 When I simply try to import the project from the root folder of my existing code, IDEA doesn't add the 'lib' folder, where all the sources are. 当我只是尝试从现有代码的根文件夹导入项目时,IDEA不会添加“lib”文件夹,其中包含所有源代码。 It should be simple, but I cannot figure it out. 它应该很简单,但我无法弄清楚。 Any hints? 任何提示?

Well, I've figured out a workaround, but not sure if it's the best solution. 好吧,我已经找到了解决方法,但不确定它是否是最佳解决方案。 One can just create a new project of type "Web", and point it to the directory containing the module's sources. 可以创建一个“Web”类型的新项目,并将其指向包含模块源的目录。 Then IDEA understands the whole structure, and you can create run configurations with Node.js. 然后IDEA了解整个结构,您可以使用Node.js创建运行配置。

In order to get additional Node features, like Intellisense for standard Node APIs, you'll still want to configure the project to be a Node project: 为了获得额外的Node功能,例如标准Node API的Intellisense,您仍然希望将项目配置为Node项目:

  1. Open the Preferences window 打开“ 首选项”窗口
  2. Click Languages & Frameworks → Node.js and NPM 单击语言和框架→Node.js和NPM
  3. In the section Coding Assistance you'll see if Node.js Core library is [not] enabled . Coding Assistance部分中,您将看到Node.js核心库是否未启用 If it is enabled, there's nothing more to do. 如果它启用,则无需执行任何操作。 If not click the Enable button 如果未单击“ 启用”按钮
  4. Leave For the whole project checked, and click Configure 保留选中整个项目 ,然后单击“ 配置”
  5. The text should now change to Node.js Core library is enabled . 文本现在应该更改为Node.js已启用核心库

Another workaround: 另一种解决方法:

If you have a version controlled Node app with no local changes, you could also create a new project of type "Node.js and NPM", point that to the directory. 如果您有一个版本控制的节点应用程序没有本地更改,您还可以创建一个类型为“Node.js和NPM”的新项目,指向该目录。 Then just use any standard settings. 然后只使用任何标准设置。

After the project is created, you can just revert the files overwritten by IDEA (eg app.js and package.json), delete any new directories and files, and you will get the additional Node features in your project. 创建项目后,您只需还原IDEA覆盖的文件(例如app.js和package.json),删除任何新目录和文件,您将获得项目中的其他Node功能。

Intellij 15 Professional Edition: Intellij 15专业版:

Import a new project -> Select the base folder of the project -> choose import form existing source. 导入新项目 - >选择项目的基本文件夹 - >选择导入表单现有源。

When Intellij is done it wont look correct so do the following: 当Intellij完成时它看起来不正确所以请执行以下操作:

1) Project Structure CMD + ; 1)项目结构CMD +;

2) Go to Modules 2)转到模块

3) Add a new module and select Node/Npm (if you dont have it then add a new plugin) 3)添加一个新模块并选择Node / Npm(如果你没有它,那么添加一个新的插件)

4) Point the source of the project to the base folder and click apply. 4)将项目源指向基础文件夹,然后单击“应用”。

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

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