CssChunkingPlugin
is an experimental plugin specifically designed for CSS module code splitting (inspired by Next.js).
It ensures that the execution order of styles matches the import order in your source code, preventing style issues.
After enabling CssChunkingPlugin, SplitChunksPlugin will no longer process CSS modules.
This means that options like optimization.splitChunks
will no longer handle CSS modules, and all CSS module code splitting logic will be handled entirely by CssChunkingPlugin.
boolean
false
Whether to strictly preserve the import order of CSS modules.
a.css
and b.css
are imported in foo.js
and bar.js
with different sequences:
Regular Mode (strict: false): Considers a.css
and b.css
to have no dependency relationship and doesn't enforce execution order, thus merging them into the same chunk.
Strict Mode (strict: true): Strictly maintains execution order consistent with import sequence, therefore packaging a.css
and b.css
into separate chunks
SplitChunksPlugin
does not consider the import order of modules when splitting code.
For JavaScript modules, this is not an issue because execution order is determined at runtime via function calls.
However, for CSS modules, the execution order is entirely determined by their order in the output files and cannot be controlled at runtime. If the order changes, it may cause style issues.
For example, importing the following CSS modules:
SplitChunksPlugin
may split them into the following chunks to satisfy maxSize
or other constraints:
This results in the execution order being b.css → a.css → c.css, which violates the original import order and may cause style errors.
CssChunkingPlugin
first splits all CSS modules, then determines which can be merged based on the import order in the source code. Modules that cannot be merged are split into separate chunks to ensure style correctness.
Because CssChunkingPlugin prioritizes preserving style execution order, it may split more chunks than SplitChunksPlugin.