複数のプロジェクトにtypescriptが必要なときに、VS Codeでnode.jsタスク/プロセスを減らす方法はありますか?

Aug 24 2020

1つのワークスペースに約10〜15個のサブgitプロジェクトがある、より大きなプロジェクトにVisual Studio Code(VSCode)を使用しています。

これらのプロジェクトはすべてtasks.jsonTypescriptなので、+ vscodeOptionを使用します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)もあれば、常にマスターになっているプロジェクトもあり、大麦は決してそれらに触れません。この問題を克服するためのベストプラクティスはありますか?

画面の私の問題:

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

回答

1 KRTirtho Oct 19 2020 at 15:17

RAM | CPU使用率を大幅に削減しますが、重要ではなくほとんど触れられていないフォルダー/プロジェクト(node_modules、.vscode、gitなど)を除外することで、vscodeが大規模なプロジェクトで使用するリソースの量を削減することもできます。

これを行うことについてのこの中程度の記事を読んでください、私はそれを書きました...それがあなたに少しでも役立つことを願っています...

VisualStudioCodeのRAM消費量を減らして高速化

TobiasSarnow Aug 25 2020 at 15:36

タスクの量を減らしようとしたため、事故の解決策を見つけましたが、各タスクの影響を減らすのはどうですか?

解決

環境変数を設定する

TSC_NONPOLLING_WATCHER="1" 

私の場合、私は.zprofile経由で調整する必要がありました

export TSC_NONPOLLING_WATCHER="1"

違いはここで完全に説明されています: https://medium.com/@julioromano/writing-typescript-on-a-laptop-this-might-improve-your-battery-life-f503dd16f019

私は2年前と同じ問題を抱えている別の人を助けることさえできました:tsc-watchはTSC_NONPOLLING_WATCHERを消費しますか?

全体として、私は本当に満足しており、私のラップトップは非常に落ち着いています(30%ではなく2-5%の使用)。