1.1.2 • Published 4 years ago

posthtml-picman v1.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

posthtml-picman npm version CI license

HTML pictures simplified

Automatically unwrap pic tag into rich picture.

Example

You write magical tag like this

<pic
  src="./images/1.jpg"
  alt="The cute cat"
></pic>

We transform it into following

<picture>
  <source
    type="image/webp"
    media="(max-width: 991px)"
    srcset="./images/1-tablet.webp 1x, ./images/1-tablet-2x.webp 2x"
  />

  <source
    media="(max-width: 991px)"
    srcset="./images/1-tablet.jpg 1x, ./images/1-tablet-2x.jpg 2x"
  />
  
  <source
    type="image/webp"
    srcset="./images/1.webp 1x, ./images/1-2x.webp 2x"
  />

  <img
    src="./images/1.jpg"
    srcset="./images/1-2x.jpg 2x"
    alt="The cute cat"
  />
</picture>

Usage

npm i posthtml-picman -D

Then add picman to your posthtml config .posthtmlrc:

{
  plugins: {
    ...
    "posthtml-picman": {}
    ...
  }
}

Options

Plugin options

NameTypeDefault valueDescription
breakpointsRecord<string, number>{}Hash table looks like { breakpointName: value } Name will be used in file paths.
retinaSuffixstring?"-2x"Suffix for using with hight dpi images.
mobileFirstbooleanfalseUse either "max-width" or "min-width" in breakpoints. true means "min-width".

Tag options

NameTypeDefault valueDescription
srcstringundefinedImage path.
imgClassstring?""Class name to apply to img tag.
picClassstring?""Class name to apply to picture tag.
altstring?"Image"Alt string. Strongly recommended to use.
1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago