包详细信息

postcss-image-inliner

bezoerb180.9kMIT7.0.1

PostCSS plugin to inline images into css

postcss, css, postcss-plugin, inline

自述文件

PostCSS Image Inliner Build Status

PostCSS plugin to inline local/remote images.

.foo {
  /* Input example */
  background-image: url('https://placehold.it/10x10');
}
.foo {
  /* Output example */
  background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAo ... ORK5CYII=');
}

Installation

npm i -D postcss postcss-image-inliner

Usage

const postcss = require('postcss');
const imageInliner = require('postcss-image-inliner');
const opts = {
  assetPaths: [], // List of directories where the inliner should look for assets
  maxFileSize: 10240, // Sets a max file size (in bytes)
};

postcss([imageInliner(opts)]);

See PostCSS docs for examples for your environment.

Options

assetPaths

  • Type: array
  • Default: [process.cwd()]
  • Example: ['http://domain.de/', 'http://domain.de/styles', 'app/images', '**/images/']
  • Required: false

List of directories/URLs where the inliner should start looking for assets. You can define local directories (globs supported) or URLs.

maxFileSize

  • Type: int
  • Default: 10240
  • Example: 0
  • Required: false

Sets a max file size (in bytes) for inlined images. Set to 0 to disable size checking.

largeFileCallback

  • Type: function
  • Default: undefined
  • Example: function (file) { console.log('big file found:', file.path); return file.path }
  • Required: false

Allows you to act on large files and change the url if you'd like. Make sure you have strict set to false when using this.

b64Svg

  • Type: bool
  • Default: false
  • Required: false

Use Base64 encoding for SVGs.

svgoPlugins

  • Type: array
  • Default: []
  • Required: false

Use custom svgo configuration for svg optimization

strict

  • Type: bool
  • Default: false
  • Required: false

Fail on error.

filter

  • Type: regex
  • Default: /^(background(?:-image)?)|(content)|(cursor)/
  • Required: false

Regex to match the CSS properties to be inlined.

更新日志

v3.0.1 / 2019-06-14

  • Test node 12
  • Bump dependencies

v3.0.0 / 2019-01-19

  • Rewrite
  • Drop node support < 8

v2.0.0 / 2017-12-17

  • Drop support for node < 6
  • Bump dependencies
  • Add strict mode

v1.0.6 / 2017-02-26

  • Bump dependencies
  • Add peer dependency

v1.0.5 / 2017-02-26

  • bump deps

v1.0.4 / 2017-01-30

  • bump deps
  • Fix the issue with "cursor" property (#156)

v1.0.3 / 2017-01-29

  • bump deps

v1.0.2 / 2016-11-22

  • removed unnecessary escape character
  • bump deps

v1.0.1 / 2016-09-28

  • bump deps

v1.0.0 / 2016-09-02

  • Minimum node.js version is 4.0 now due to upstream changes.
  • bump deps

v0.3.1 / 2016-05-10

  • travis tweaks
  • bump deps & eslint-config
  • added glob tests

v0.3.0 / 2016-02-05

  • handle content property (#61)
  • bump deps

0.2.0 / 2015-12-10

  • Added 'strict' option (#28)
  • Bump dependencies

0.1.3 / 2015-09-24

  • Better svg encoding + b64Svg option (#1)

0.1.2 / 2015-09-24

  • Outsourced asset-resolver

0.1.1 / 2015-09-20

  • Fixed filesize check

0.1.0 / 2015-09-19

  • Initial release