Offline Code Compression -- SublimeText2 with Reg Replace Plugin
Both files should be in the User folder
In reg_replace.sublime-settings
"compress_space": {
"find": "\t|\n",
"replace": "",
"greedy": true,
"case": false,
"scope_filter":
[
"source.c, source.js, source.java, source.css",
"-comment", "-!string"
]
},
"compress_comments": {
"find": ".*?\n",
"replace": "",
"greedy": true,
"case": false,
"scope_filter": ["comment"]
},
"compress_opening_brackets": {
"find": "(\\[|\\(|\\{)\\s+",
"replace": "\\1",
"greedy": true,
"case": false,
"scope_filter":
[
"source.c, source.js, source.java, source.css",
"-comment", "-!string"
]
},
"compress_closing_brackets": {
"find": "\\s+(\\)|\\}|\\])",
"replace": "\\1",
"greedy": true,
"case": false,
"scope_filter":
[
"source.c, source.js, source.java, source.css",
"-comment", "-!string"
]
},
"compress_special": {
"find": "\\s*(:|;|,)\\s*",
"replace": "\\1",
"greedy": true,
"case": false,
"scope_filter":
[
"source.c, source.js, source.java, source.css",
"-comment", "-!string"
]
}
In Default.sublime-commands
{
"caption": "Reg Replace: Compress Code",
"command": "reg_replace",
"args": {
"replacements": [
"compress_comments",
"compress_space",
"compress_special",
"compress_opening_brackets",
"compress_closing_brackets"
]
}
}
These have only been tested with CSS and JS files.
They should work with C and java files as well.
Any suggestions will be appreciated.
If you ask me why I would compress code when I'm offline, I don't know, I had the idea when I was on the plane. I know this might be useless. :)
Written by Po Chen
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Css
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#