gulp-css-file2base64
v0.1.1
Published
Gulp plugin. Adds a function file2base64 in css.
Downloads
12
Maintainers
Readme
gulp-css-file2base64
Gulp plugin. Adds a function file2base64, which loads the file and inserts the contents of a file as a base64 string.
Table of Contents
Install
npm install --save-dev gulp-css-file2base64
Options
debug
(Boolean)Option log to console. In debug mode will be displayed warning unsuccessful convert your files into base64 string. This option is disabled by default.
Enabling debug mode:
... .pipe(file2base64({debug: true})) ...
Example usage
This example shows how to automatically insert the contents of files as a string encoded in base64
gulpfile.js
var gulp = require('gulp');
var file2base64 = require('gulp-css-file2base64');
gulp.task('file2base64', function () {
gulp.src('./static/css/*.css')
.pipe(file2base64())
.pipe(gulp.dest('./static/cache/'));
});
Contents of file "./static/css/main.css"
/* Example of inserting font */
@font-face {
font-family: 'RubPTSans';
src: url("data:font/opentype;base64,file2base64('../fonts/RubPTSans-Bold-Italic.ttf')") format("truetype");
font-weight: bold;
font-style: italic;
}
/* Example of inserting image */
.ico-home {
background-image: url("data:image/png;base64,file2base64('../icons/ico-home.png')");
}
Result contents of file "./static/cache/main.css"
/* Example of inserting font */
@font-face {
font-family: 'RubPTSans';
src: url("data:font/opentype;base64,AAEAAAAQAQAABAAATFRTSANFAgsAAAIMAAAADU9TLzKGcICtAAABiAAAAGBWRE1YdPh8dgAAAhwAAAXgY21hcAl/E/EAAAkYAAABJGN2dCAAFAAAAAALtAAAAAJmcGdtBlmcNwAACjwAAAFzZ2x5ZgVUitYAAAu4AAABMGhkbXgFN250AAAH/AAAARxoZWFk+k9YkAAAAQwAAAA2aGhlYQZTAvMAAAFEAAAAJGhtdHgHgAAQAAAB6AAAACRsb2NhATABMAAADOgAAAAUbWF4cAIWAZ4AAAFoAAAAIG5hbWXaYu7lAAAM/AAAAWJwb3N0+R8+aAAADmAAAABRcHJlcLgAACsAAAuwAAAABAABAAAAAQAAABh1KV8PPPUAGQPoAAAAAMkbarAAAAAAz5+qNAAQAAACWALGAAAACQACAAAAAAAAAAEAAAMg/zgAyAPoABD/y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AYQByAFIAdQBiACAAQQByAGkAYQBsACAAUgBlAGcAdQBsAGEAcgBSAHUAYgBBAHIAaQBhAGwALQBSAGUAZwB1AGwAYQByAAAAAgAAAAAAAP+1ADIAAAAAAAAAAAAAAAAAAAAAAAAAAAAJAAAACwACAAMAEQECAQMBBAEFB3VuaTA0MzEHdW5pMDQ0MAd1bmkwNDQzBE5VTEwAAAA=") format("truetype");
font-weight: bold;
font-style: italic;
}
/* Example of inserting image */
.ico-home {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAJlJREFUOI3N0k8KQVEYhvHfFUZMmRjJBpSBjSibsgvKwAZkrEhWICMGsgkm59Ttdv/J5L711On0PV/vqUOTk2AVSH6Vu9jgE1ijU1fu45CSI3v0quQhrjly5IJBkTzBvUSO3DDOyjO8a8iRF6Z5LXY15G1aaBW9B0csAqeioXbJgmdoBMuiobIGtfL3guwXnWMUzg+cK+4bkC+4QTlQ8DpbDgAAAABJRU5ErkJggg==");
}
How to use with sass?
gulpfile.js
var gulp = require('gulp');
var file2base64 = require('gulp-css-file2base64');
gulp.task('sass', function () {
gulp.src('./static/sass/*.scss')
.pipe(sass())
.pipe(file2base64())
.pipe(gulp.dest('./static/cache/'));
});