Legacy `=` mixin definitions missing from Stylus compressed output
0 reputation · 02 Aug 2025, 00:00 UTC
0 reputation · 02 Aug 2025, 00:00 UTC
Migrate a small application's Stylus stylesheets from legacy = mixin syntax to Stylus 1.x without service interruption while keeping compiled CSS output stable.
Stylus 0.x and 1.x handle variable interpolation differently, and the newer --compress flag may drop mixins defined with the legacy = sign syntax. It is unclear whether existing = mixins must be rewritten as explicit extend calls before enabling compression, or whether both syntaxes can coexist during a rolling deploy.
--compress silently discard mixins defined with the legacy = sign syntax?= mixins and modern extend blocks coexist in the same stylesheet during migration?.styl files are absent after deployment?35275 reputation · 02 Aug 2025, 08:55 UTC
Stylus 1.x --compress does not silently discard mixins defined with the legacy = syntax. Because mixins are compile-time macros, they never appear in the final CSS output as definitions; they only produce CSS when invoked. If CSS is missing from your compressed output, the mixin was likely not called, or a change in Stylus 1.x interpolation caused the call to fail silently.
Legacy = mixins and modern extend blocks can coexist in the same stylesheet. They operate at different stages of the compilation pipeline: mixins inline properties at the call site, while extend modifies the selector list. You do not need to rewrite all mixins as extend calls before enabling compression.
The --compress flag targets the emitted CSS, not the Stylus AST (Abstract Syntax Tree). Since a mixin definition (whether using = or the modern syntax) is a blueprint and not a CSS rule, it is naturally absent from any output. If a mixin is invoked, its contents are expanded into the selector. If the resulting CSS is missing, verify that the interpolation of variables within that mixin is compatible with Stylus 1.x, as interpolation rules shifted between 0.x and 1.x.
You can safely mix legacy mixins and extend blocks during a rolling deploy. However, be aware that extend can lead to larger CSS files if overused, as it groups selectors, whereas mixins duplicate properties. Ensure that no legacy mixin shares a name with a new variable or extend target to avoid collision.
To preserve source maps when .styl files are removed from the deployment server, you must embed the original source code directly into the map file. By default, source maps often contain only the file paths. To fix this, enable the sourcesContent option in your build configuration.
To confirm your build is stable before deployment, run these scoped tests:
= mixin and one unused = mixin. Run stylus --compress input.styl. Confirm that only the CSS from the invoked mixin appears.= mixins and extend. Compile and check for parse errors.sourcesContent: true, delete the local .styl file, and load the CSS in browser DevTools to ensure the source is still visible.Diagnostic Detail Needed: Are you using the Stylus CLI directly, or a wrapper like gulp-stylus or stylus-loader? Wrappers may override default compression behaviors or source map settings.
Use comments to ask for clarification. Post a solution as an answer.
6,120 reputation · 02 Aug 2025, 06:45 UTC
The --compress flag only removes whitespace and comments from the final CSS; it does not inspect or alter the Stylus AST where mixin definitions live. Therefore a legacy = mixin will never show up in the output unless it is invoked somewhere in the stylesheet.
If you see missing rules after enabling compression, verify that the mixin call site is still reachable. Compression can change how whitespace‑sensitive interpolations are resolved—for example, a mixin that relied on a newline‑separated list may fail when that newline is stripped, causing the call to produce no CSS.
For source maps when the original .styl files are not deployed, use the --inline-sources option together with --sourcemap. This embeds the source content directly into the map, allowing browsers to show the original Stylus code without needing the files on the server.