当多个项目需要打字稿时,有没有办法减少 VS Code 中的 node.js 任务/流程?
Is there a way to reduce node.js tasks/ processes in VS Code while typescript is required for multiple projects?
我正在为一个更大的项目使用 Visual Studio 代码 (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),有些项目一直在 master 上,我大麦从不碰它们。您有解决此问题的最佳实践吗?
我的屏幕问题:
我的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"
}
}
我意外地找到了解决方案,因为我试图减少任务的数量,但是如何减少每个任务的影响呢?
解决方案
设置环境变量
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 年前遇到的同样问题:
Does tsc-watch consume TSC_NONPOLLING_WATCHER?
总而言之,我真的很高兴,我的笔记本电脑非常安静(使用率为 2-5%,而不是 30%)。
虽然它减少了如此多的 RAM|CPU 使用,但您也可以通过排除一些不重要且几乎没有接触过的东西来减少 vscode 使用的资源量 folders/projects 例如:node_modules、.vscode、git 等...
阅读这篇关于如何做的中篇文章,我写的...希望它能对您有所帮助...
我正在为一个更大的项目使用 Visual Studio 代码 (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),有些项目一直在 master 上,我大麦从不碰它们。您有解决此问题的最佳实践吗?
我的屏幕问题:
我的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"
}
}
我意外地找到了解决方案,因为我试图减少任务的数量,但是如何减少每个任务的影响呢?
解决方案
设置环境变量
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 年前遇到的同样问题: Does tsc-watch consume TSC_NONPOLLING_WATCHER?
总而言之,我真的很高兴,我的笔记本电脑非常安静(使用率为 2-5%,而不是 30%)。
虽然它减少了如此多的 RAM|CPU 使用,但您也可以通过排除一些不重要且几乎没有接触过的东西来减少 vscode 使用的资源量 folders/projects 例如:node_modules、.vscode、git 等...
阅读这篇关于如何做的中篇文章,我写的...希望它能对您有所帮助...