当多个项目需要打字稿时,是否有办法减少VS Code中的node.js任务/进程?

如何解决当多个项目需要打字稿时,是否有办法减少VS Code中的node.js任务/进程?

我正在使用Visual Studio Code(VSCode)进行较大的项目,在一个工作区中大约有10到15个子git项目。

所有这些项目都是Typescript,所以我使用tasks.json + vscode选项Tasks: Manage Automatic Tasks in Folder

这导致10-15个节点进程,每个进程使用大约1-4%的CPU使用率。不幸的是,我有多个工作空间开放,所以我最终有很多节点进程,不仅消耗了我的内存,而且还消耗了我的CPU

It heats up my pc and I want to know if this can be prevented. 

有些项目我经常更改(2-3),有些项目总是掌握在我的手下,而我大麦却从未碰过它们。您是否有最佳实践来克服这个问题?

我在屏幕上的问题

my screen

我的code --status(摘要):

CPU %   Mem MB     PID  Process
1      197   28044  code main
1     1114   28046     gpu-process
0        0   28048     utility
0     1442   28051     window (textarea.vue — d-reporting-vue-ws)
...
15       66   97382           electron_node cli.js 
0      328   28391       extensionHost
0       66   30325         electron_node tsserver.js 
0      721   30327         electron_node tsserver.js 
0       66   30358           electron_node typingsInstaller.js typesMap.js 
0      393   30361         /nvm/versions/node/v12.16.3/bin/node //.vscode/extensions/dbaeumer.vscode-eslint-2.1.8/server/out/eslintServer.js --node-ipc --clientProcessId=28391
0        0   97363         electron_node ms-vscode.js bundle.js 
0        0   28947       watcherService
1        0   31594       node ...-reporting-ws/w-articleloader/node_modules/.bin/tsc -p ...-reporting-ws/w-articleloader/tsconfig.json --watch
2        0   31596       node ...-reporting-ws/w-api-redis/node_modules/.bin/tsc -p ...-reporting-ws/w-api-redis/tsconfig.json --watch
2        0   31598       node ...-reporting-ws/w-api-i18n/node_modules/.bin/tsc -p ...-reporting-ws/w-api-i18n/tsconfig.json --watch
2        0   31599       node ...-reporting-ws/w-api-elasticsearch/node_modules/.bin/tsc -p ...-reporting-ws/w-api-elasticsearch/tsconfig.json --watch
1        0   31600       node ...-reporting-ws/w-api-db/node_modules/.bin/tsc -p ...-reporting-ws/w-api-db/tsconfig.json --watch
4        0   31601       node ...-reporting-ws/d-lib-hb/node_modules/.bin/tsc -p ...-reporting-ws/d-lib-hb/tsconfig.json --watch
3      197   31603       node ...-reporting-ws/node_modules/.bin/tsc -p ...-reporting-ws/d-reporting-hb/tsconfig.json --watch
3        0   31604       node ...-reporting-ws/w-resource-manager/node_modules/.bin/tsc -p ...-reporting-ws/w-resource-manager/tsconfig.json --watch
1        0   31605       node ...-reporting-ws/w-logger-winston/node_modules/.bin/tsc -p ...-reporting-ws/w-logger-winston/tsconfig.json --watch
3        0   31607       node ...-reporting-ws/w-mailer/node_modules/.bin/tsc -p ...-reporting-ws/w-mailer/tsconfig.json --watch
2        0   31608       node ...-reporting-ws/w-core/node_modules/.bin/tsc -p ...-reporting-ws/w-core/tsconfig.json --watch
1        0   31609       node ...-reporting-ws/w-base-types/node_modules/.bin/tsc -p ...-reporting-ws/w-base-types/tsconfig.json --watch
2        0   31610       node ...-reporting-ws/w-fulfillment-lib/node_modules/.bin/tsc -p ...-reporting-ws/w-fulfillment-lib/tsconfig.json --watch
3        0   31612       node ...-reporting-ws/w-rm-type-pug/node_modules/.bin/tsc -p ...-reporting-ws/w-rm-type-pug/tsconfig.json --watch
2        0   31615       node ...-reporting-ws/w-database-abstraction-couchdb/node_modules/.bin/tsc -p ...-reporting-ws/w-database-abstraction-couchdb/tsconfig.json --watch
2        0   31737       node ...-reporting-ws/w6-compatibility/node_modules/.bin/tsc -p ...-reporting-ws/w6-compatibility/tsconfig.json --watch
1        0   31738       node ...-reporting-ws/w-number-group/node_modules/.bin/tsc -p ...-reporting-ws/w-number-group/tsconfig.json --watch

我的tsconfig

{
"compilerOptions": {
    "target": "ES2016","module": "CommonJS","moduleResolution": "Node","resolveJsonModule": true,"esModuleInterop": true,"rootDir": "src","outDir": "./","sourceMap": true,"declaration": true,"strict": true,"noImplicitAny": true,"noImplicitReturns": true,"noUnusedLocals": true,"noUnusedParameters": true,"removeComments": true,"pretty": true,"forceConsistentCasingInFileNames": true,"allowJs": true,"baseUrl": ".","paths": {
        "*": ["types/*"]
    }
},"include": [
    "src"
],"exclude": [
    "node_modules"
]}

最后是我的task.json(摘要)

{
        "type": "typescript","tsconfig": "d-lib-hb/tsconfig.json","option": "watch","problemMatcher": [
            "$tsc-watch"
        ],"runOptions": {
            "runOn": "folderOpen"
        }
    }

解决方法

尽管它减少了大量的RAM | CPU使用率,但是您还可以通过排除一些不重要且几乎不涉及的文件夹/项目来减少vscode用于较大项目的资源量,例如:node_modules,.vscode,git等...

阅读有关此操作的中篇文章,我写道...希望它对您有所帮助...

Make Visual Studio Code Less RAM Consuming & Faster

,

我找到了一个意外的解决方案,因为我试图减少任务量,但是如何减少每个任务的影响呢?

解决方案

设置环境变量

TSC_NONPOLLING_WATCHER="1" 

就我而言,我必须通过{p>

.zprofile

这里可以很好地解释差异:https://medium.com/@julioromano/writing-typescript-on-a-laptop-this-might-improve-your-battery-life-f503dd16f019

我什至可以帮助另一个两年前遇到同样问题的人: Does tsc-watch consume TSC_NONPOLLING_WATCHER?

总的来说,我真的很高兴,我的笔记本电脑也相当安静(使用率是2-5%,而不是30%)。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res