node-sass-cache-busted-url
Sass custom function to replace URLs with ones with cache buster strings. Usable in node-sass.
USAGE
Let case as below:
// example.scss body
// cache-busters.json// expected to generate by programs like gulp-rev
JavaScript API
var sass = ;var cacheBustedUrl = ; // Generate cache buster object which has url as key and cache-busted url as valuevar cacheBusters = ; // Determine function signature used in Sass filevar functionSignature = "cache-busted-url($url)"; // Apply cache bustersvar bustersDefinedBuster = cacheBustedUrl; // Render CSS with pass `functions` optionvar compiled = sass;console;// body {// background: url("/images/bg-3d1fc66b0a4bb6af83ea234d1f510408.png") no-repeat; }
Command-line interface
node-sass
accepts functions
options to specify file which defines Sass custom functions.
At CLI, specify path to file which defines URL-cache busted URL mapping by environment variable CACHE_BUSTERS_PATH
.
$ CACHE_BUSTERS_PATH=cache-busters.json \
$(npm bin)/node-sass \
--functions=$(npm root)/node-sass-cache-busted-url/custom-functions.js \
example.scss
body {
background: url("/images/bg-3d1fc66b0a4bb6af83ea234d1f510408.png") no-repeat; }
Customize function name
As advanced usage of library, you can change the name of Sass custom function. Let's use it as image-url
function:
// example.scss body
// cache-busters.json
Then execute JavaScript. Note that the value of functionSignature
is changed:
var sass = ;var cacheBustedUrl = ; // Specify cache busters filevar cacheBusters = ; // Determine function signature used in Sass filevar functionSignature = "image-url($url)"; // Apply cache bustersvar bustersDefinedBuster = cacheBustedUrl; // Render CSS with pass `functions` optionsvar compiled = sass;console;// body {// background: url("/images/bg-3d1fc66b0a4bb6af83ea234d1f510408.png") no-repeat; }
LICENSE
LGPLv3 or later. See LICENSE for details.