• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

adam-lynch/gulp-image-data-uri: Converts images to data URIs

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

adam-lynch/gulp-image-data-uri

开源软件地址(OpenSource Url):

https://github.com/adam-lynch/gulp-image-data-uri

开源编程语言(OpenSource Language):

CoffeeScript 89.4%

开源软件介绍(OpenSource Introduction):

gulp-image-data-uri

NPM version Build Status Windows Build Status Dependency Status


A Gulp plugin for converting images to inline data-URIs. Intended to be a simple single-purpose wrapper for heldr/datauri (well, datauri.template).

Installation

npm install gulp-image-data-uri

Usage for Gulp ^4.0.0

const gulp = require('gulp'),
      imageDataURI = require('gulp-image-data-uri');

// path variables
var imgSrc = 'src/img/*',
    cssDist = 'dist/css/',

// the task
exports.datauri = function () {
    return src (imgSrc)
    .pipe(imageDataURI())
    .pipe(dest(cssDist))
}

The Ol' fashion way

Reminder: The task() API isn't the recommended pattern anymore - export your tasks as shown above.

var gulp = require('gulp');
var imageDataURI = require('gulp-image-data-uri');

gulp.task('prepare', function() {
    gulp.src('./images/*')
        .pipe(imageDataURI()) 
        .pipe(gulp.dest('./dist'));
});

gulp.task('default', ['prepare']);

For example output, see test/expected. See Examples for more information.

Options

customClass

An optional function. If omitted, the class added is just the file's basename.

The function is called with two arguments; the default class name and the Vinyl file object. It must return the new class (string). See Examples for more information.

template

An optional object. See the Custom CSS template examples below.

template.file

A string which is a path to a template file (note: this doesn't have to be a .css file). This must be given if you want to use a custom template. An example file:

.{{className}} {
    background: url("{{dataURISchema}}");
}

The className and dataURISchema variables will always be passed to your template.

  • className is the name of the file or if you use the customClass option then it's whatever your function returns.
  • dataURISchema is the data URI.

Note: classNameSuffix is also reserved (by a module used underneath) but don't use it.

template.variables

An optional object of variable names to variables like this:

{
    defaultMargin: '.1rem'
}

These will be passed to your template along with the className, dataURISchema and classNameSuffix variables this module gives you (these are reserved variables).

template.engine

An optional function which accepts the data (as an object) as its only parameter and returns a string.

Consider lodash.template as example. If your favorite templating engine does support a compile + render shorthand, you just need to point the handler after a given template path, otherwise you will need to create a template adapter.

template.adapter

An optional function which accepts the template content (string) as its only parameter and returns a template function (or engine).

Some templating engines do not have a shorthand to compile + render at the same call. In this specific case we can create a template wrapper as the example below:

Examples

For example output, see test/expected.

Custom CSS templates

These examples expand on the Combining into one CSS file example but you don't have to concatenate them if you like.

Contributing

See CONTRIBUTING.md

Anything missing?

Create an issue / pull-request


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap