vscode auto run task on save code & automatic debug All In One
vscode auto run task on save code & automatic debug All In One
save code & automatic run command script
VSCode Tasks API
Lots of tools exist to automate tasks like linting, building, packaging, testing, or deploying software systems.
Examples include the TypeScript Compiler, linters like ESLint and TSLint as well as build systems like Make, Ant, Gulp, Jake, Rake, and MSBuild.
https://code.visualstudio.com/docs/editor/tasks
task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello"
}
]
}
package.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "lint",
"problemMatcher": ["$eslint-stylish"]
}
]
}
https://code.visualstudio.com/docs/editor/tasks#_task-autodetection
steps
Command
+ Shfit
+ P
/ Command
+ Shfit
+ B
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello"
},
{
"type": "npm",
"script": "test",
"group": "test",
"problemMatcher": [],
"label": "npm: test",
"detail": "node ./js-solutions/008\\ string-to-integer-atoi.js"
}
]
}
{
"name": "leetcode",
"version": "1.0.0",
"description": "leetcode",
"main": "index.js",
"scripts": {
"test": "node ./js-solutions/008\\ string-to-integer-atoi.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/xgqfrms/leetcode.git"
},
"keywords": [
"leetcode"
],
"author": "xgqfrms",
"license": "MIT",
"bugs": {
"url": "https://github.com/xgqfrms/leetcode/issues"
},
"homepage": "https://github.com/xgqfrms/leetcode#readme"
}
node.js watch ❌
"scripts": {
"test": "node --watch ./js-solutions/008\\ string-to-integer-atoi.js"
},
node.js watch file change by command line
fs.watchfile & fs.watch
md5 hash
https://thisdavej.com/how-to-watch-for-files-changes-in-node-js/
https://www.bezkoder.com/node-js-watch-file-changes/
automatic debug
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
}
watch
https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
extensions / plugins
Automatically Execute Bash Commands on Save in VS Code
https://betterprogramming.pub/automatically-execute-bash-commands-on-save-in-vs-code-7a3100449f63
// settings.json
{
//...
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.pug$",
"cmd": "pug ./ --doctype html --pretty"
},
{
"match": "\\.ejs$",
"cmd": "ejs-cli '*.ejs' --out dest/ --options options.json"
}
]
}
}
{
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files.'"
},
{
"match": "\\.txt$",
"cmd": "echo 'I am a .txt file ${file}.'"
},
{
"match": "\\.js$",
"cmd": "echo 'I am a .js file ${file}.'"
},
{
"match": ".*",
"cmd": "echo 'I am ${env.USERNAME}.'"
}
]
}
}
https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave#:~:text=Placeholder Tokens
https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave#placeholder-tokens
vscode extension
https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.triggertaskonsave
https://github.com/Gruntfuggly/triggertaskonsave
refs
https://stackoverflow.com/questions/68059778/auto-run-command-from-vscode-extension-on-file-save
©xgqfrms 2012-2025
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16014265.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
2021-03-16 nslookup & ip address All In One
2021-03-16 NPC All in One
2020-03-16 CSS Dark Mode
2020-03-16 ES2020 All in One
2020-03-16 eui & search select
2020-03-16 canvas graph chart
2020-03-16 Error: Cannot find module 'spdy'