Last active
August 29, 2015 14:00
-
-
Save hernan604/11057601 to your computer and use it in GitHub Desktop.
js minifier for vim (using Vim::X + perl)
This file contains hidden or 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
| package JsMinifier; | |
| use strict; | |
| use warnings; | |
| use Vim::X; | |
| use JavaScript::Packer; | |
| =head2 .vimrc | |
| perl push @INC, '/home/hernan/mnt/desktop/home/hernan/mnt/sda4/files/perl/vimx/lib/'; | |
| perl use JsMinifier; | |
| map ,jsmini :call Vjs_minifier( line("'<"), line("'>") ); | |
| =head2 usage in vim | |
| :call Vjs_minifier( line("'<"), line("'>") , "best" ); | |
| :call Vjs_minifier( line("'<"), line("'>") , "obfuscate" ); | |
| =cut | |
| sub Vjs_minifier :Vim(args) { | |
| my $range_init = shift; | |
| my $range_end = shift; | |
| my $compress_option = shift||"best"; | |
| my @range = ( $range_init .. $range_end ); | |
| my @lines = map { vim_line($_)->content } @range; | |
| my $js_src = join "", @lines; | |
| vim_delete( @range ); | |
| my $packer = JavaScript::Packer->init(); | |
| vim_prepend( | |
| $packer->minify( \$js_src , { compress => $compress_option } ) | |
| ); | |
| } | |
| 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment