MinifyOptions
computeCalcExpression?: boolean;
computeShorthand?: boolean;
computeTransform?: boolean;
evaluateMixins?: boolean;
fastMode?: boolean;
inlineCssVariables?: boolean;
keepMixins?: boolean;
mergeRules?: boolean | MergeRulesEnum;
minify?: boolean;
minifyAST?: boolean;
nestingRules?: boolean;
optimizeSelectors?: boolean;
parseColor?: boolean;
pass?: number;
removeDuplicateDeclarations?: string | boolean | string[];
removeEmpty?: boolean;
removePrefix?: boolean;
}
Hierarchy (View Summary)
- MinifyOptions
Index
Properties
Properties
Optionalcompute Calc Expression
Compute css math functions
Optionalcompute Shorthand
Compute shorthand properties
Optionalcompute Transform
Compute css transform functions
Optionalevaluate Mixins
Evaluate css mixins and custom functions: the @apply rules are replaced by the body of the mixin they reference,
the private variables (@private, mixin arguments and the custom properties of the rule) are substituted.
the custom function calls (--fn(1px)) are replaced by the result of the function.
see https://drafts.csswg.org/css-mixins-1/
import {transform} from '@tbela99/css-parser';
const css = `
@mixin --only-descs(--arg) {
color: var(--arg);
& * { color: var(--arg, red); }
}
.foo {
@apply --only-descs(green);
}
`;
const result = await transform(css, {evaluateMixins: true, expandNestingRules: true});
console.log(result.code);
// .foo,.foo *{color:green}
Optionalfast Mode
Fast mode: the ast is not minified and the rules are not merged, the values are minified when they are rendered. The output is larger and the minification is faster. It sets the default value of these options, an option given explicitly takes precedence:
{
minify: false,
mergeRules: MergeRulesEnum.None,
}
import {transformSync} from '@tbela99/css-parser';
const result = transformSync(css, {fastMode: true});
Optionalinline Css Variables
Inline css variables
Optionalkeep Mixins
Keep the mixins and the custom functions once they are evaluated, see evaluateMixins. By default, the evaluated mixins and custom functions, and the mixins that are not referenced, are dropped and replaced with a comment
Optionalmerge Rules
Merge the adjacent rules (MergeRulesEnum, true is a shortcut for MergeRulesEnum.All, false
for MergeRulesEnum.None).
- MergeRulesEnum.All: the rules that share declarations are merged when the output is smaller
- MergeRulesEnum.Identical: only the rules that have the same declarations are merged, the size of the
output is not computed:
.a{color:red}.b{color:red}is merged into.a,.b{color:red} - MergeRulesEnum.None: the rules that have different selectors are not merged
The default is MergeRulesEnum.All when the ast is minified, MergeRulesEnum.None otherwise. With
minify: false, MergeRulesEnum.Identical and MergeRulesEnum.All merge the rules without
minifying the ast: the adjacent rules and keyframes rules that have the same selector and the adjacent at-rules
that have the same prelude are merged (@font-face is not merged), the last @keyframes of a name is kept, the
rules that have different selectors are merged as above. The other minifications are not applied.
import {transformSync, MergeRulesEnum} from '@tbela99/css-parser';
// the adjacent rules that have the same declarations are merged, the ast is not minified
const result = transformSync(css, {minify: false, mergeRules: MergeRulesEnum.Identical});
Optionalminify
Enable minification
Optionalminify AST
enable ast minification
Optionalnesting Rules
Generate nested rules
Optionaloptimize Selectors
Optimize the selectors (default true): remove the redundant selectors, factor the selectors with :is().
false only applies when nestingRules is false: the nesting of the rules reads the optimized selectors.
Optionalparse Color
Parse color tokens
Optionalpass
Define minification passes.
Optionalremove Duplicate Declarations
Remove duplicate declarations from the same rule. if passed as a string array, duplicated declarations are removed, except for those in the array
import {transform} from '@tbela99/css-parser';
const css = `
.table {
width: 100%;
width: calc(100% + 40px);
margin-left: 20px;
margin-left: min(100% , 20px)
}
`;
const result = await transform(css, {
beautify: true,
validation: true,
removeDuplicateDeclarations: ['width']
}
);
console.log(result.code);
Optionalremove Empty
Remove empty ast nodes
Optionalremove Prefix
Remove css prefix
Minify options