Holism is the idea that various systems should be viewed as wholes, not merely as a collection of parts.
Build-time Automatic image transformation and Holistic management
This is a convention over configuration library, and all you need is to follow our convention
Having β‘οΈ
βββ image@2x.holistic.png
οΈWill produce β¬οΈ
βββ image@2x.holistic.png
βββ .holistic (you can hide this directory)
β ββ image@2x
β ββ derived.image@1x.jpg
β ββ derived.image@1x.webp
β ββ derived.image@1x.avif
β ββ derived.image@2x.jpg
β ββ derived.image@2x.webp
β ββ derived.image@2x.avif
| ββ derived.scss
β ββ derived.image@2x.meta.js
The same principle will be applied during the import - instead of importing image@2x.holistic.png
you will get a
pointer to all files below
Note: holistic-image does not produce
png
output (configurable) as the end user is expected to usewebp
oravif
holistic-image
is looking for files named accordingly - image.holistic.png
(or jpg) and derives
the "missing" ones - optimized jpg
, webp
and avif
If the source file named as image@2x.jpg
(Figma standard), then @1x
version will be generated automatically
autogenerate
option enabled (default)// generate-images.js
import {deriveHolisticImages} from "holistic-image/api";
deriveHolisticImages(
/root folder*/
process.argv[2],
/*mask*/ process.argv[3],
// /*optional*/ squoosh ecoders with options
)
And then in package.json
// package.json
"autogen:images": "yarn generate-images.js $INIT_CWD 'src/**/*'",
// package.json
"autogen:images":"holistic-image derive $INIT_CWD 'src/**/*'"
"validate:images":"holistic-image validate $INIT_CWD 'src/**/*'"
import { holisticImage } from 'holistic-image/webpack';
webpack.config = {
module: {
rules: {
oneOf: [holisticImage, yourFileLoader],
// .. rest of your config
},
},
};
automatic image generation will be enabled if process.env.NODE_ENV
is set to development
to fine control settings use:
import { holisticImagePresetFactory } from 'holistic-image/webpack';
import { holisticImageLoader } from 'holistic-image/webpack';
Easy config (for storybook for example), everything will work as well
import { holisticImage } from 'holistic-image/webpack';
webpack.config = {
module: {
rules: {
holisticImage,
yourFileLoader,
// .. and rest of your config
},
},
};
import image from './image.holistic.jpg';
// ^ not an image, but HolisticalImageDefinition
image = {
base: [1x, 2x],
webp: [1x, 2x],
avif: [1x, 2x],
[META]: {width, height, ratio}
}
import { Image } from 'holistical-image/react';
import image from './image.holistic.jpg';
import imageXS from './imageXS.holistic.jpg';
<Image src={image} media={{ 'max-width: 600px': imageXS }} />;
// π 6-12 images generated, the right picked, completely transparent
While this library provides d.ts
for the file extension it can be more beneficial to provide your own ones, as you did
for .jpg
and other static asses already
declare module '*.holistic.jpg' {
import type { HolisticalImageDefinition } from 'holistic-image';
const content: HolisticalImageDefinition;
export default content;
}
Configuration is possible in two modes:
folders starting from .
already expected to be hidden for IDE, but keep in mind - derived files are expected to be
commited.
You can use idea-exclude to automaticaly configure Idea-based solutions to exclude these folders
idea-exclude holistic-images "src/**/.holistic"
"files.exclude": {
"**/.holistic": true
}
MIT