当多个项目需要打字稿时,是否有办法减少VS Code中的node.js任务/进程? [英] Is there a way to reduce node.js tasks/ processes in VS Code while typescript is required for multiple projects?

查看:69
本文介绍了当多个项目需要打字稿时,是否有办法减少VS Code中的node.js任务/进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Visual Studio Code (VSCode) for a bigger project where we have around 10 to 15 sub git projects in one workspace.

所有这些项目都是Typescript,所以我使用 tasks.json + vscode选项任务:管理文件夹中的自动任务

All these projects are Typescript so I use tasks.json + vscode Option Tasks: Manage Automatic Tasks in Folder.

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

This leads to 10-15 nodes processes with each using around 1-4% CPU usage. Unfortunately I have multiple work spaces open so I end up having a lot of node processes not just only consuming my memory also my cpu.

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

一些我经常更改的项目(2-3),有些总是在掌握中,而我大麦却从未碰过。您是否有最佳方法来克服此问题?

Some projects I change often (2-3) and some are always on master and I barley never touch them. Do you have any best practices how to overcome this problem?

我在屏幕上的问题:

我的代码-状态(摘要):

My code --status (snippet):

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"
        }
    }


推荐答案

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

I found a solution on accident because I tried to reduce the amount of tasks but what about reducing the impact of each task?

解决方案

设置环境变量

TSC_NONPOLLING_WATCHER="1" 

在我的情况下,我必须通过以下方式调整 .zprofile

In my case i had to adjust .zprofile via

export TSC_NONPOLLING_WATCHER="1"

区别在这里得到了完美的解释: https://medium.com/@julioromano/writing-typescript-on-a-laptop-这可能会改善您的电池寿命-f503dd16f019

The difference is perfectly explained here: https://medium.com/@julioromano/writing-typescript-on-a-laptop-this-might-improve-your-battery-life-f503dd16f019

我甚至可以帮助另一个有两年前同样问题的人:
tsc-watch是否消耗TSC_NONPOLLING_WATCHER?

I even could help another person with the same problem he had 2 years ago: Does tsc-watch consume TSC_NONPOLLING_WATCHER?

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

All in all im really pleased and my laptop is quite and calm (2-5% usage instead of 30%).

这篇关于当多个项目需要打字稿时,是否有办法减少VS Code中的node.js任务/进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆