Smart asset packaging for Rails, Sinatra, and Stasis.
AssetPackager, but with the following changes:
- Uses file size and super fast hashing (Murmur3) to determine if a new compressed package should be created
- clean-css for css compression
- Framework agnostic (adapters provided for Rails 2, Rails 3, Sinatra, and Stasis)
gem install smart_asset
Install npm packages
npm install uglify-js clean-css -g
require 'sinatra/base' require 'smart_asset' class Application < Sinatra::Base include SmartAsset::Adapters::Sinatra end
Create Configuration File
By default, SmartAsset will look for assets in
Create Packaged Assets
cd to your project and run
If your project is Git version controlled, only the assets that have changed are repackaged.
Otherwise, all packages generate every time.
Include Packages in Your Template
Migrating from AssetPackager
- Install SmartAsset
- Instead of running
rake asset:packager:build_all, run
You may add extra options to your
Below are the default values (excluding
You may use environment variables with the
smart_asset command to alter its behavior.
Output commands that are running, leave the tmp file around for inspection
Only compress a specific package
Use a default modified time other than Time.now for non-version controlled files
Get compression warnings from UglifyJS
Forks and contributions to this project are much appreciated, but please make sure the specs run!
To run the basic specs:
There are also framework specs to make sure the helpers work in Rails 2, Rails 3, and Sinatra 1: