Giter Site home page Giter Site logo

postcss-image-inliner's Introduction

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.

postcss-image-inliner's People

Contributors

bezoerb avatar greenkeeperio-bot avatar xhmikosr avatar dependabot[bot] avatar juice10 avatar u-v avatar

Watchers

 avatar

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.