Last active
July 3, 2018 19:45
-
-
Save circa10a/52c9896aaf857e683a048e1d5141f47f to your computer and use it in GitHub Desktop.
One line to safely minimize js files using sed(there will be single spaces left to not break variable assignment)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires appropriate semi-colons | |
FILE_PATH=$(pwd); for i in $(ls $FILE_PATH/*.js); do sed -i 's|//.*||g; /\/\*/,/*\//d; /^\s*$/d;' $i && sed -i ':a;N;$!ba;s/\n/ /g; s/ //g' $i; done | |
# Before | |
# const os = require('os'); | |
# function num(num){ | |
# return 5 + num | |
# } | |
# // Sample Comment | |
# /* More | |
# Comments | |
# */ | |
# module.exports = { | |
# "randNum": num(5), | |
# "host": { | |
# "name": os.hostname(), | |
# "homeDir": os.homedir() | |
# } | |
# }; | |
# After | |
# const os = require('os'); function num(num){ return 5 + num } module.exports = { "randNum": num(5), "host": { "name": os.hostname(), "homeDir": os.homedir() } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment