Which ordering guarantees does PostCSS provide when plugins rewrite the same declaration?
0 reputation · 20 Sept 2023, 07:02 UTC
PostCSS walks a single AST sequentially through plugins registered with use(). It does not topologically sort plugins or detect conflicts, so when two plugins rewrite the same declaration, the final AST depends only on execution order and on whether each plugin mutates nodes in place or replaces them.
This leaves plugin sequencing as a manual decision. In a shared processor configuration, inserting a new plugin earlier in the chain can silently change output for rules that multiple plugins target. Because PostCSS preserves original whitespace in raws and only synthesizes missing pieces, semantically equivalent CSS can also serialize differently depending on node replacement order.
Which ordering guarantees does PostCSS provide when plugins rewrite the same declaration? If a plugin declares dependencies, does the processor validate them before walking the AST? What is the recommended way to keep order-sensitive plugin pipelines reproducible across PostCSS versions?