4.0.4 • Published 6 years ago

@billykwok/sqip.macro v4.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

sqip.macro

Build Status Babel Macro

Webpack sqip-loader implemented as babel-plugin-macros

Usage

Similar to nodejs require call:

import sqip from "sqip.macro";

const preview = sqip("./image.jpg");

Example of usage in create-react-app

import sqip from "sqip.macro";

const { d, w, h } = sqip("./cover-image.jpg", {
  numberOfPrimitives: 3, // default is 12
  blur: 5, // default is 0,
  outputMode: 2, // default is 0
  // Explanation:
  // * 0 is Reverse Aspect Ratio Mode: { dataUrl: string, ratio: number }
  // * 1 is Aspect Ratio Mode: { dataUrl: string, ratio: number }
  // * 2 is Dimension Mode: { dataUrl: string, width: number, height: number }
  // * 3 is Direct Mode: output dataUrl directly as a string
  trimOutput: false, // trim "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 " at the beginning and "%3c/svg%3e" at the end because they are the same for every image
});

const SomeComponent = () => (
  <div
    style={{
      backgroundImage: `url(${coversqip}`,
      backgroundSize: "cover",
      backgroundRepeat: "no-repeat",
    }}
  >
    <img src={d} alt="description" width={w} height={h} />
  </div>
);

Credits

Based on pveyes/raw.macro.

License

MIT

4.0.4

6 years ago

4.0.3

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago