Skip to content

Instantly share code, notes, and snippets.

@nadyshalaby
Last active December 23, 2024 22:42
Show Gist options
  • Save nadyshalaby/5c37c6161a695933298192ccfc981ceb to your computer and use it in GitHub Desktop.
Save nadyshalaby/5c37c6161a695933298192ccfc981ceb to your computer and use it in GitHub Desktop.
npm install -g uglify-js clean-css-cli
{
"filewatcher.commands": [
{
"match": "(?<!\\.min)\\.(js|css)$",
"isAsync": true,
"cmd": "minify ${file} > ${fileDirname}/${fileBasenameNoExt}.min${fileExtname}",
"event": "onFileChange"
}
]
}
{
"filewatcher.commands": [
{
// npm install uglify-js -g
"match": "\\.js$",
"notMatch": "\\.min\\.js$",
"isAsync": true,
"cmd": "uglifyjs ${file} -o ${fileDirname}/${fileBasenameNoExt}.min.js -c -m --verbose",
"event": "onFileChange"
},
{
// npm install clean-css-cli -g
"match": "\\.css$",
"notMatch": "\\.min\\.css$",
"isAsync": true,
"cmd": "cleancss -o ${fileDirname}/${fileBasenameNoExt}.min.css ${file}",
"event": "onFileChange"
}
]
}
@nadyshalaby
Copy link
Author

I've recreated the VSCode settings file with the file watcher configuration. Now when you save any JS or CSS file in VSCode, it should automatically create or update the minified version. You can check the Output panel (View -> Output -> File Watcher) to see any errors or output from the minification process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment