在Visual Studio代码中的keybinding上运行npm命令

在Visual Studio代码中的keybinding上运行npm命令,npm,visual-studio-code,key-bindings,Npm,Visual Studio Code,Key Bindings,我想在使用webpack保存时捆绑js文件 这最好使用webpack watch来完成。但不管怎样 下面的答案是我在谷歌搜索的结果,我希望在某个时候对某些人有用。使用npm在VSC中的save上运行webpack bundling。。。或者您喜欢的任何其他npm命令,比如编译typescript 将.vscode/tasks.json添加到项目中: { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the

我想在使用webpack保存时捆绑js文件

这最好使用webpack watch来完成。但不管怎样


下面的答案是我在谷歌搜索的结果,我希望在某个时候对某些人有用。

使用npm在VSC中的save上运行webpack bundling。。。或者您喜欢的任何其他npm命令,比如编译typescript

.vscode/tasks.json
添加到项目中:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "command": "npm",
    "isShellCommand": true,
    "showOutput": "never",
    "suppressTaskName": true,
    "tasks": [
        {
            "taskName": "bundle",
            "args": ["run", "bundle"],
            "isBuildCommand": true,
            "showOutput": "never"
        }
    ]
}
编辑
keybindings.json
(文件>首选项>键盘快捷键)

workbench.action.tasks.build
是一个内置的vsc钩子。请看这里:

也可以通过在VSC中访问该任务

  • Ctrl+P
  • 键入
    任务
    +空格
  • 查看建议的任务或继续键入其名称

  • keybindings.json

    {
    “键”:“ctrl+shift+alt+b”,
    “命令”:“workbench.action.terminal.sendSequence”,
    “args”:{
    “文本”:“npm运行测试\r”
    },
    },
    
    Related:我认为让webpack查看文件是一种更好的方法,而且更容易设置。
    // Place your key bindings in this file to overwrite the defaults
    [
        {
            "key" : "ctrl+s",
            "command" : "workbench.action.tasks.build"
        }
    ]