Giter VIP home page Giter VIP logo

gulp-inline-base64's Introduction

GULP inline-base64

This helper will inject images and fonts into your css files.

Warning ! This technique is really efficient with small files (<14 Kb) cause it avoids DNS requests and makes the page loading faster. But for larger files it will be a mistake to use it !

Install it

npm install --save-dev gulp-inline-base64

Use it

Here is my sass config. As you can see, I use the 'maxSize' option to specitfy that files larger than 14kb are not injected into the css file.

var sass = require('gulp-sass'),
	inline_base64 = require('gulp-inline-base64'),
	autoprefixer = require('gulp-autoprefixer');
...

// SASS
gulp.task('sass', function() {
    return gulp.src([
        path_src + '/css/**/*.scss',
        '!' + path_src + '/css/**/_*.scss'
    ])
    .pipe(sass({
        includePaths: [
            path_src + '/css/',
            'bower_components/',
        ],
        imagePath: path_src
    }))
    .pipe(inline_base64({
        baseDir: path_src,
        maxSize: 14 * 1024,
        debug: true
    }))
    .pipe(autoprefixer("last 2 version", "> 1%", {
        cascade: true
    }))
    .pipe(gulp.dest(path_tmp + '/css'))
});

Options

  • baseDir : the root path for assets
  • useRelativePath : overrides baseDir; root path is relative to the input file's directory
  • maxSize : define the limit size of injected assets
  • debug : show debug messages

Force asset injection

In your css file, just add ,true to the image url : it will force the asset to be injected in base64 in css file, event if the maxSize is reached.

div.logo {
	background: transparent url(/img/logo.png,true) no-repeat center center;
}

gulp-inline-base64's People

Contributors

domoritz avatar felthy avatar g33klabs avatar sbbowers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gulp-inline-base64's Issues

Cache busting suffix breaks inlining

Web assets often use suffixes to prevent stale cached files from loading, e.g. font/abc.ttf?ad8d7e2d177d2473aecd9b35d16211fb or font/abc.eot?#iefix.

Unfortunately, this prevents gulp-inline-base64 from inlining those files, without going through the extra step of renaming the files to those exact names (which is brittle and may break compatibility with other programs).

EDIT: This definitely breaks compatibility with Windows, which doesn't allow a literal ? in filenames.

Syntax "url(./image.png,true)" is against the specs

I'm having errors in CSS or SASS syntax analyzers when trying to follow your syntax.

For it to be more consistent to URL rules, I suggest to change (or make a alternative) it to

url("./image.png?embed") - so it'll be a valid url parameter. It has to be inside the quotes, if they're present, not outside of them, like now

@font-face url problem

I have a issue about css @font-face.

When url, e.g. "url('myfont-webfont.eot?#iefix')" have suffix "?#iefix", i get error: "file not found".

Any solution, please?

Inline embedding doesn't work without quotes

Tested on win 10.

Inline transformer only works if url is taken into quotes, line this: url("../images/logo.png"). Is it intentional? Either way, in documentation there is an example, showing the usecase without quotes

Remove gulp-util dependency

Please remove gulp-util from dependencies, as it is deprecated now and the package has critical vulnerability.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.