Skip to content

A PostCSS plugin to generate responsive images and companion css using eleventy-img

License

Notifications You must be signed in to change notification settings

sygint/postcss-11ty-responsive-bg-img

Repository files navigation

postcss-11ty-responsive-bg-img

A PostCSS plugin to generate responsive images and companion css using eleventy-img.

basic example

input:

/* input css */
.foo {
  background-image: responsive-bg-img(images/happy-cat.png, 400, 640, 768)
}
# starting directory tree

images
├── happy-cat.png

output:

/* output css */

.foo {
  background: url("/img/HOdUYjZ3EM-400.webp");
}
  
@media (min-width: 640px) {
  background-image: url("/img/HOdUYjZ3EM-640.webp");
}
@media (min-width: 768px) {
  background-image: url("/img/HOdUYjZ3EM-768.webp");
}
# ending directory tree

images
├── happy-cat.png
optimized-images
├── HOdUYjZ3EM-400.webp
├── HOdUYjZ3EM-640.webp
└── HOdUYjZ3EM-768.webp

Usage

Step 1: Install plugin:

npm install --save-dev postcss postcss-11ty-responsive-bg-img

Step 2: Check you project for existed PostCSS config: postcss.config.js in the project root, "postcss" section in package.json or postcss in bundle config.

If you do not use PostCSS, add it according to official docs and set this plugin in settings.

Step 3: Add the plugin to plugins list:

module.exports = {
  plugins: [
+   require('postcss-11ty-responsive-bg-img'),
    req
  ]
}

About

A PostCSS plugin to generate responsive images and companion css using eleventy-img

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published