Guard::Packr automatically compresses/obfuscates javascript files when modified (using Guard + Packr).
Add to your Gemfile
:
gem 'guard-packr'
…and bundle install
.
Dependencies:
…you will need, but installed by Bundler they will be. – Yoda
Use the Guard generator:
$ guard init packr
…to generate default Packr-guard (with notes) into your Guardfile
In your Guardfile
, something like:
guard 'packr', :extension => '.packed.js', :shrink_vars => true, :private => true, :base62 => false, :protect => %w[_this that] do # == IMPORTANT: # # - Ensure that you don't write rules that owerwrite your source files! # To avoid that either use custom "extension" (see above), or temporarily # generated files as source (e.g. app/assets/javascripts => tmp/javascripts). # # - This guard should be placed after any javascript processing (guard-sprockets, guard-jammit, etc.) # within your Guardfile - naturally (Packr makes no sense for pre-processing javascript). # watch('tmp/javascripts/.*\.js') end
To read more about the Packr-options, see Packr.
When in doubt, see Guard.
:extension => '.packed.js' # File-extension for the packed javascript file. :shrink_vars => true, # Compress local variable names. :private => true, # Obfuscate 'private' identifiers, i.e. names beginning with a single underscore. :base62 => false, # Encode the program using base 62. :protect => %w[_this that] # Variable names to protect from compression.
This gem was developed for a tiny special case at Merchii, so feel free to send pull-requests with enhancements of any kind (features, bug-fixes, documentation, tests, etc.) to make it better or useful for you as well.
Released under the MIT license.
Copyright © Merchii, Jonas Grimfelt