DEV Community

Teerasak Vichadee
Teerasak Vichadee

Posted on

Create VSCode User Snippet

I have enough! My VSCode always autocomplete command that I don't need when I'm about to export CommonJS module (or module.exports).

And I'm too lazy to manually type module.exports to export module in CommonJS.

To fix this, just add user snippet!

  1. Open command pallete (cmd + Shift + p)
  2. Type "user snippet" ... it should suggest "Snippets: Configure User Snippets" then hit Enter!
  3. The pallete should display a list of snippet, then choose "New Global Snippet file..." VSCode will open a new file
  4. Add this code
{
  "CommonJS export": {
    "scope": "javascript,typescript",
    "prefix": "mdep",
    "body": [
      "module.exports = {$1}"
    ],
    "description": "Export module as CommonJS"
  }
}
Enter fullscreen mode Exit fullscreen mode

What does it mean?

  • "CommonJS export" -- the name of this snippet
  • "scope": "javascript,typescript" -- this snippet will be use on JS and TS
  • "prefix": "mdep" -- I will just type mdep and got my module.exports
  • "body" -- this is the template it will generate my expected code

That's it!

Top comments (0)