Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ grunt.initConfig({
// Replace references to the images in the compiled js and css files, and the html views
filerev_replace: {
options: {
assets_root: 'tmp/assets/'
assets_root: 'tmp/assets/',
cdn_url: 'http://subdomain.domain.xxx' // CDN url, leave blank ('') for no url
},
compiled_assets: {
src: 'tmp/assets/compiled/*.{css,js}'
Expand Down
8 changes: 5 additions & 3 deletions tasks/filerev_replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ module.exports = function(grunt) {
var assets_root = this.options().assets_root;
var views_root = this.options().views_root || assets_root;
var assets_paths = filerev_summary_to_assets_paths( assets_root );
var cdn_url = this.options().cdn_url || '';


this.files[0].src.forEach( function( view_src ){
var changes = replace_assets_paths_in_view( assets_paths, view_src, views_root );
var changes = replace_assets_paths_in_view( assets_paths, view_src, views_root, cdn_url );
log_view_changes( view_src, changes );
});
});
Expand Down Expand Up @@ -58,7 +60,7 @@ module.exports = function(grunt) {
return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}

function replace_assets_paths_in_view( assets_paths, view_src, views_root ) {
function replace_assets_paths_in_view( assets_paths, view_src, views_root, cdn_url ) {
var view = grunt.file.read( view_src );
var changes = [];

Expand All @@ -67,7 +69,7 @@ module.exports = function(grunt) {

if( grunt.file.arePathsEquivalent( asset_path.toLowerCase(), asset_src.toLowerCase() ) ) {
changed = true;
return p1 + p2 + asset_dest + p4 + p5;
return p1 + cdn_url + p2 + asset_dest + p4 + p5;
} else {
return match;
}
Expand Down