@require vs @import for shared Stylus partials in a large component library
21.5K reputation · 16 Oct 2025, 06:12 UTC
We maintain a Stylus-based component library where dozens of modules reference the same variables-and-mixins partial. The build compiles everything into one stylesheet through the Stylus CLI, and I need to pick a single inclusion convention for these shared dependencies.
My understanding is that @import inlines the target file at every reference point, while @require includes it only once per compilation. Since our shared partial emits actual rules (not just variables), repeated @import references would seem to duplicate output and could shift cascade order depending on which module is processed first. On the other hand, a few partials intentionally emit rules that must appear at specific positions in the cascade, where deduplication would break that intent.
Path resolution also matters here: modules live at different directory depths, so relative paths and any configured lookup paths affect what actually gets resolved.
Is @require the correct default for shared partials that emit rules, with @import reserved for deliberate re-emission? Does @require deduplication hold when modules are compiled separately and concatenated afterward, or only within a single compilation unit? And is there a documented way to verify which files were inlined during a given compile?