Skip to content

Instantly share code, notes, and snippets.

@wbyoko
Created February 27, 2013 20:21
Show Gist options
  • Save wbyoko/5051346 to your computer and use it in GitHub Desktop.
Save wbyoko/5051346 to your computer and use it in GitHub Desktop.
These are snippets of code i'm using to swap out development versions of scripts to prebuilt mins that are in the same directory if available. this code is added to htmlprocessor.js in the grunt-usemin plugin ~ node_modules/grunt-usemin/lib/htmlprocessor.js
<!-- place at ~line 3 -->
<!-- 'use strict'; -->
<!-- var path = require('path'); -->
<!-- start include -->
var fs = require('fs');
var useMinIfAvailable = function (filePath) {
var minFilePath = filePath.replace(/(\.js|\.css)$/g,'.min$1');
if (fs.existsSync(minFilePath)) {
return minFilePath;
}
return filePath;
};
<!-- end include -->
<!-- place at ~line 106 -->
<!-- if (block && last) { -->
<!-- var asset = l.match(/(href|src)=["']([^'"]+)["']/); -->
<!-- if (asset && asset[2]) { -->
<!-- start replace -->
last.src.push(useMinIfAvailable(path.join(originDir, asset[2])));
<!-- end replace -->
<!-- // RequireJS uses a data-main attribute on the script tag to tell it -->
<!-- // to load up the main entry point of the amp app -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment