postcss-variable-compress
Version:
PostCSS plugin cleans up the variable names and saves space. It can will reduce your css variable to smaller variables
99 lines (78 loc) • 1.86 kB
text/typescript
import postcss, { Root } from 'postcss';
import variableCompress, { variableCompressParameters } from './splitFiles';
async function run (input: string | { toString(): string; } | Root, output: string, opts?: variableCompressParameters[] | (string | ((e: any) => any))[] | undefined) {
let result = await postcss(
[]
).process(input, { from: undefined });
expect(result.css).toEqual(output);
expect(result.warnings()).toHaveLength(0);
}
it('Shorten css variables', async () => {
await run(
`:root {
--first-color:
--second-color:
--2:
}
background-color: var(--first-color);
color: var(--second-color);
}
background-color: var(--second-color);
color: var(--first-color);
}
--first-color:
}
background-color: var(--first-color);
color: var(--second-color);
}
.section-title {
color: var(--primary-color, var(--black,
}
code {
--5:
}`,
`:root {
--0:
--1:
--2:
}
background-color: var(--0);
color: var(--1);
}
background-color: var(--1);
color: var(--0);
}
--0:
}
background-color: var(--0);
color: var(--1);
}
.section-title {
color: var(--primary-color, var(--3,
}
code {
--5:
}`,
[
'--primary-color',
'2',
(e: string | string[]) => e.includes('special'),
(e: string) => e === '--5'
]
);
});
it('No reloading', async () => {
await run(`:root{--first-color:
await run(`:root{--second-color:
});
it('Base array check or no array', async () => {
await run(`:root{}`, `:root{}`);
});