Generates asset fingerprints and appends to an existing rails manifest
npm install grunt-rails-asset-digest
|192||downloads in the last day|
|725||downloads in the last week|
|7 117||downloads in the last month|
|Version||0.4.0 last updated a month ago|
|Keywords||gruntplugin, rails, assets, fingerprinting, manifest|
Rails Version Support
Rails 4 significantly changed how the asset manifest is generated. As such if you are still on Rails 3.2 (using manifest.yml) you should use
v0.3.2 of this plugin
npm install email@example.com --save;
v0.4.0 tracks support for Rails 4 and above.
Generates fingerprinted assets and appends entries to a sprockets-rails manifest.json
This plugin is intended to be used by those who are integrating a grunt workflow alongside of the sprockets-rails. As such, this task expects to be run after the sprockets-rails has generated an asset manifest.json file.
This approach works well in that it only manages fingerprinting and manifest modification for the files that are explicitly managed in the
files property and it guarantees that existing entries generated by sprockets-rails will not be touched.
Why would I use this?
How would I integrate this task?
Adjust your rails deployment lifecycle to run this task prior to deploying/uploading assets (whether to a CDN, or just in
public/assets which is where this task will dump fingerprinted assets by default). Here's an example configuration in a Capistrano deploy setup that uses Lineman to manage the lifecycle of a rich-client application that still lives within a rails source tree. (The same techniques will work with vanilla Grunt, you'll just have to manage the task aliasing yourself)
# linemans config/application.coffee appTasks: common: [ "sass" "coffee" "concat" ] dist: [ "uglify" "rails_asset_digest" "clean" ]
# config/deploy.rb after 'assets:compress', 'assets:compile_with_lineman', 'assets:upload' task :compile_with_lineman logger.important "Compiling other assets with Lineman" run "lineman build" # run grunt tasks in common and dist phases end
Note: this is a very narrowly focused task, and you might not get much use out of it :)
This plugin requires Grunt
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-rails-asset-digest --save-dev
The "rails_asset_digest" task
In your project's Gruntfile, add a section named
rails_asset_digest to the data object passed into
Given the configuration in the Overview section above, you can expect
grunt rails_asset_digest to output the following to
And the associaated fingerprinted entries in manifest.json like so:
The digest algorithm used to fingerprint the assets, note: Rails 4 (via the sprockets-rails plugin) doesn't actually use an MD5 hash based on the contents of the file anymore, it just uses a random hex digest. It doesn't matter what value is in the hash of the filename as long as the entry in the manifest matches the name of the file on disk.
The location of the rails asset path
The name of the manifest file, so you can provide your own secret to prevent people guessing the name if so desired.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
- clone this repo
- 2014-02-05 v0.4.0 support rails 4 + sprockets-rails manifest.json format
- 2014-02-04 v0.3.2 no-op: align version number with supported rails version
- 2013-10-15 v0.2.0 bugfix: asserts the output of written files actually exist
- 2013-10-15 v0.1.1 bugfix: normalizes asset path to append trailing /
- 2013-10-14 v0.1.0 Initial release.