Ruby wrapper and Rails asset pipeline integration for optimize-js.
About
This gem is ruby wrapper for optimize-js. It allows you to invoke optimize-js from ruby. For Rails users this gem automatically integrates optimize-js into sprockets.
Installing gem
If you are using bundler.
Add to your Gemfile:
gem 'optimize-js', '~> 1.0'
If you are not using bundler.
Run in your terminal:
gem install optimize-js
Require gem in your ruby sources:
require 'optimize-js'
Using gem
API is quite simple.
# OptimizeJS.perform(javascript_source, optimize_js_options)
OptimizeJS.perform('!function() {}()') # => !(function() {})()
Using in Rails
There is no need to do anything.
Gem will automatically register OptimizeJS::SprocketsProcessor
using register_bundle_processor
so all your JavaScript assets will be optimized.
Updating optimize-js to the latest version
- Install gem dependencies:
bundle install
- Run:
bundle exec rake optimize_js
This rake task will do several things:
- Clone latest git tag
- Install npm dependencies
- Install browserify
- Install uglifyjs
- Make web-version
- Minify web-version
- Write version to optimize-js/version.rb
- Cleanup
Running tests
- Install gem dependencies:
bundle install
- Run tests:
bundle exec rake test
Things to work on
Write integration tests.Test on different versions of sprockets.Test on different versions of rails.Test on different versions of ruby.- Sprockets without Rails.
- Typos in README.