Node 工具导致 Visual Studio 速度变慢

5

有没有任何配置可以设置,使节点工具不会减慢Visual Studio的速度?我不能卸载节点工具,因为我需要使用它,但它会大大减慢vs的速度,仅仅打开项目属性窗口就变得非常痛苦。

我尝试隐藏node_modules文件夹,以为可能是在读取这些文件,但这并没有改变任何东西。

有什么建议吗? 谢谢

3个回答

2
你说你无法卸载Node工具,但最终我不得不卸载Node工具才能使用Visual Studio。在默认设置和安装了Node工具的情况下,Visual Studio会自动安装package.json,然后自动分析这些文件以尝试创建代码提示智能感知,Node工具将创建一个非常大的.ntvs_analysis.dat缓存文件。在所有这些强制性的设置和分析之后,如果我没有通过CTRL-ALT-DEL退出5-30分钟的冻结,它会在几分钟后再次崩溃。我会看到内存和CPU使用率的飙升,直到我的笔记本电脑冻结,而.ntvs_analysis文件只会变得更大。我花了一段时间才意识到我仍然可以在没有Node工具的情况下使用和创建Node项目。
将package.json文件放置在解决方案文件的父目录中,这样Visual Studio就没有机会分析(和崩溃),试图为大型node_modules文件夹构建Intellisense。该文件可以位于根C:\驱动器下,但应根据项目范围放置在合适的位置。(隐藏node_modules文件夹也可以起作用,但同一项目的新用户也需要隐藏他们的文件夹,并且他们需要在VS尝试自动安装package.json之前这样做)。
使用命令窗口,在package.json文件夹的位置运行npm install。
任务运行器资源管理器将搜索父目录中的package.json。它将加载在package.json的“scripts”标签中定义的任务,以及在gruntfile.js或gulp.js文件中定义的任务。
选择ASP.Net Web应用程序作为项目类型,但像往常一样构建您的node项目。
如果所有其他方法都失败,请使用其他IDE(请感受到我对Visual Studio共享的挫败感)。我推荐Sublime。
这种解决方法仍然使得按照我们的团队文件组织方式在TFS中工作具有挑战性。
如果像你说的那样,你必须要使用node工具,请关闭其他插件和智能感知功能。在遵循我的建议后,我意识到使用记事本反而更好(哎呀!)。
你可以忽略某些目录进行分析——
以下是来自https://github.com/Microsoft/nodejstools/wiki/Projects#ignoring-directories-for-analysis的引用:

It may be useful to ignore certain directories, such as client side JavaScript, from analysis. There are many reasons to do this but the biggest two are:

  • the particular directory is large and takes a great deal of time to analyse.
  • The directory contains client side code that doesn't need to be analysed.

There is a property in the .njsproj file that can be used to ignore directories. The following code can be added to the project file under a PropertyGroup:

<PropertyGroup>
     <!-- Specifies the directories which are ignored. Any paths 
        which contain these directory names will be ignored. 
        The directory name must completely match and no wild cards 
        are allowed
    -->
<AnalysisIgnoredDirectories>bower_components;dir_not_included</AnalysisIgnoredDirectories>
</PropertyGroup>

Note that all filepaths containing the specified string will be ignored. So if you specify dir_not_included, every filepath containing dir_not_included will be ignored (including subdirectories).

This property takes precedence over other settings. This includes whether you included the file in your project or not. If you specify a directory here as ignore it will not be analysed.

你不是唯一一个为此烦恼的开发者,尽管微软宣传支持node.js,但实际上支持还很薄弱。如果我团队里的一些非常聪明的人和我在使用node项目时遇到问题,我们都会与Visual Studio进行斗争。
我希望有人能给出比我更好的答案,因为我也对更好的解决方案感兴趣。

0

已经过去了将近一年多的时间,vs2017发布了,但情况仍然没有改变。我有强烈的怀疑,VS不尊重AnalysisIgnoredDirectories属性,或者在每次gulp/npm构建后对更改的文件进行深度扫描。

而且我们在这方面并不孤单,可以查看这个线程:https://github.com/Microsoft/nodejstools/issues/1506

当我从微软那里接收到进一步的信息时,我会更新这个话题。在此之前,是的,我们要坚持使用简单的notepad.exe


0

我刚刚删除了外部文件夹的所有内容。 在我的情况下,它是:

X:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 {Version} \ Web \ External)

在那之前,我已经决定它是TFS(因为地理位置上TFS服务器与我相距太远:互联网,防火墙等)- 在解决方案中的每个修改后,我都等待至少15秒(在此期间Visual Studio被阻塞,无响应)。

但现在,当node.js和其他外部内容被删除时 - 几乎两天我可以毫无延迟地工作。 我知道node.js本身应该正常工作 - 但我没有去碰它,它按默认设置运行,并且看起来需要改进;)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接