nodejs grunt 圖片轉換 插件

grunt-image-embed 轉換在css裏的圖片

npm install grunt-image-embed

Documentation

This task has two required properties, src and destsrc is the path to your stylesheet and dest is the file this task will write to (relative to the grunt.js file). If this file already exists it will be overwritten.

An example configuration looks like this:

grunt.initConfig({
  imageEmbed: {
    dist: {
      src: [ "css/styles.css" ],
      dest: "css/output.css",
      options: {
        deleteAfterEncoding : false
      }
    }
  }});

Optional Configuration Properties

ImageEmbed can be customized by specifying the following options:

  • maxImageSize: The maximum size of the base64 string in bytes. This defaults to 32768, or IE8's limit. Set this to 0 to remove the limit and allow any size string.

  • baseDir: If you have absolute image paths in your stylesheet, the path specified in this option will be used as the base directory.

  • deleteAfterEncoding: Set this to true to delete images after they've been encoded. You'll want to do this in a staging area, and not in your source directories. Be careful.

Skipping Images

Specify that an image should be skipped by adding the following comment directive after the image:

background: url(image.gif); /*ImageEmbed:skip*/

 

grunt-inline-imgbase64 圖片轉換

npm install grunt-inline-imgbase64

Usage Examples

下面的例子会内联html和css文件内的imageUrl。支持本地和远程文件。

inline_imgbase64: {
        options:{
            exts:['jpg','jpeg','png','gif'], //需要替换的文件类型
            tag:'__inline', // 设定此值时,带此参数的imageUrl才会被替换
            maxLength:40 //只用于远程图片大小限制,图片大小超过maxLength时不转换,单位KB
        },
        dist: {
            src: ['test/dist/*.*'],
            dest: ['tmp/']
        }
    }

 

转载于:https://my.oschina.net/homeemail/blog/373877

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值