I want to bundle js files on save using webpack.
This is best accomplished using webpack watch. But whatever...
In the answers below is the result of my googling, which I hope will be useful to somebody at some point.
You can do that in the Preferences -> Keyboard Shortcuts section. Search for "Run Python File in Terminal", select the command and press the little + sign on the left.
If you're calling npm from the VSCode terminal, you need to restart VSCode first before trying again. If you still get the error, then try restarting your computer first. The error should be gone after you restart. Now you should be able to install any npm package to your local computer with npm install command.
In VS Code, you only need to use a shortcut to run your code. That shortcut is Ctrl + Alt + N. There are a few more ways to run code. Pressing F1 and then choosing “Run Code” also works.
Use npm to run webpack bundling on save in VSC ... or any other npm command you like, like compiling typescript.
Add a .vscode/tasks.json
to your project:
{
// 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"
}
]
}
Edit keybindings.json
(File>Preferences>Keyboard Shortcuts).
// Place your key bindings in this file to overwrite the defaults
[
{
"key" : "ctrl+s",
"command" : "workbench.action.tasks.build"
}
]
The workbench.action.tasks.build
is a built-in vsc hook. See here: https://code.visualstudio.com/docs/customization/keybindings#_tasks
The task can also be accessed in VSC via
Ctrl+P
task
+ spacekeybindings.json
{
"key": "ctrl+shift+alt+b",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "npm run test\r"
},
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With