.my-component-button--primary) to short identifiers (e.g., .a, .b, .aB) in both template files and style files during compilation. This reduces the size of template and CSS output in mini-program packages.
Enabling compression
Setexperiments.compressCssClassName to true for defaults, or to a configuration object for fine-grained control:
Configuration options
Option reference
strategy
strategy
The compression algorithm to use. Currently only
'lite' is supported.In lite mode the compiler:- Skips
app.acss(and equivalent global style files) entirely — class names defined there are added to the exclusion list. - Skips template files that contain dynamic class bindings such as
class="prefix-{{condition}}"and their corresponding style files.
prefix and surfix
prefix and surfix
prefix is prepended and surfix is appended to every generated class name.prefix is empty, the generator automatically uses a letter-only alphabet to ensure the first character of a class name is never a digit or underscore (which would be invalid CSS).include and exclude
include and exclude
Both accept an array of This compresses only files under
RegExp objects. exclude takes priority over include.src/components, except those under src/components/legacy.except
except
An array of class name strings that are never renamed. Use this for class names that are referenced dynamically at runtime, in third-party component libraries, or injected from outside the mini-program.
alphabet
alphabet
The set of characters used when generating compressed names. Defaults to:The generator starts with length-1 names, then increments length as the namespace fills up (at 80% capacity).
customAttributeNames
customAttributeNames
Some component libraries use custom class-like attributes (e.g.,
inner-class, wrap-class). List them here so MorJS compresses them alongside the standard class attribute.classNameFilter
classNameFilter
A function
(className: string, filePath: string) => boolean. Return true to compress the class name, false to leave it unchanged.disableDynamicClassDetection
disableDynamicClassDetection
By default, any template file containing a dynamic class binding like
class="{{expr}}" is skipped entirely (along with its style file) to avoid breaking runtime class concatenation.Set to true to compress all files regardless of dynamic bindings. Use a function for per-file control:success callback
success callback
Called after the webpack compilation finishes. Receives a
Map<string, string> mapping original class names to compressed names.Limitations
- Only
litestrategy is currently available. - Global style files (
app.acss,app.wxss) are always skipped. Class names defined in them are added to the exclusion list and will not be renamed in any other file either. - Template files containing dynamic class bindings (
class="{{...}}") are skipped by default, along with their corresponding style files. - Compression runs with webpack
parallelismset to1to guarantee that global style processing completes before per-file compression begins. - The feature is not supported for
web,web-pro, orweex-protargets.