thehardwarestore.ai

where AI agents shop for the right tools

$ show webpack/stylus-loader

[account ↗] [repo ↗] APPLICATION ★ 493 99 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

This is a webpack loader that compiles Stylus (.styl) files into CSS. It acts as a bridge between the webpack build system and the Stylus CSS preprocessor, handling import resolution (including glob patterns, node_modules, webpack aliases, and tilde imports), source maps, custom Stylus options, and URL rewriting. The architecture follows the standard webpack loader pattern: it receives the source code, parses options via a JSON schema, renders Stylus using an implementation (defaulting to the `stylus` package), and outputs either the compiled CSS along with source map and dependency list. It supports dual ESM/CJS builds and is compatible with webpack 5 and optionally Rspack. The primary entry point is `src/index.js`, which exports the loader function. Core utilities live in `src/utils.js`, which includes a custom Stylus evaluator that overrides import resolution to delegate to webpack's resolver, utility functions for normalizing options and source maps, and a dependency collector that traverses the Stylus AST to report all imports to webpack's build graph. The loader integrates deeply with webpack's module resolution (aliases, `resolve.byDependency`, custom conditions) and supports advanced Stylus features like CSS module exports, `@import` and `@require`, `@block`, and the `url()` resolver. Externally, it depends on the `stylus` npm package as the core preprocessor, and on webpack's loader API. It is actively maintained, with recent major version bumps aligning with Node.js runtime requirements (v9.0.0 requires Node >=22.11.0). The codebase is well-tested with a comprehensive test suite covering numerous edge cases in import resolution, error handling, and option combinations. While the loader itself is webpack-specific, several internal patterns (custom evaluator, dependency resolution, URL handling) demonstrate non-obvious craftsmanship and could inform similar integrations for other CSS preprocessors.

RATING7.8/10
QUALITY7.2/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS53
VELOCITY0.74
OPEN ISSUES7
CLOSED ISSUES169
LAST COMMIT1 month ago
@types/stylus (npm) ^0.48.43
normalize-path (npm) ^3.0.0
tinyglobby (npm) ^0.2.12
@babel/cli (npm) ^7.24.7
@babel/core (npm) ^7.29.6
@babel/preset-env (npm) ^7.24.7
@changesets/cli (npm) ^2.30.0
@changesets/get-github-info (npm) ^0.8.0
@types/node (npm) ^22.19.19
@types/normalize-path (npm) ^3.0.2
benchmark (npm) ^2.1.4
bootstrap-styl (npm) ^5.0.9
cspell (npm) ^10.0.0
css-loader (npm) ^7.1.2
del (npm) ^8.0.1
del-cli (npm) ^7.0.0
eslint (npm) ^9.32.0
eslint-config-webpack (npm) ^4.4.2
husky (npm) ^9.1.3
lint-staged (npm) ^17.0.5
memfs (npm) ^4.9.3
nib (npm) ^1.1.2
npm-run-all (npm) ^4.1.5
prettier (npm) ^3.3.2
raw-loader (npm) ^4.0.2
style-loader (npm) ^4.0.0
stylus (npm) ^0.64.0
typescript (npm) ^6.0.3
webpack (npm) ^5.101.0
Files by Type (count)
Other (.styl)
140
JavaScript
34
JSON
13
Other (.snap)
7
Other (no ext)
5
Markdown
4
YAML
3
CSS
3
Other (.cjs)
2
TypeScript
2
Git Ignore
1
Other (.mjs)
1
Files by Type (size)
JSON
495KB
Other (.snap)
360KB
JavaScript
141KB
Markdown
32KB
Other (.styl)
8KB
TypeScript
7KB
YAML
4KB
Other (no ext)
1KB
Other (.cjs)
395B
Git Ignore
352B
Other (.mjs)
197B
CSS
145B

The LLM identified 1 files worth highlighting for reuse:

This module contains the core extensions to Stylus that enable webpack-aware import resolution and dependency tracking. The `createEvaluator` function returns a subclass of Stylus's Evaluator that overrides `visitImport` to resolve imports via webpack's resolver (supporting file, glob, and alias resolution) instead of Stylus's default filesystem-based resolution. This pattern is reusable for any CSS preprocessor loader that needs to integrate with webpack's module system. The module also exports `getStylusImplementation` (handles custom `stylus` package detection and version checks), `getStylusOptions` (normalizes options including `define`, `import`, `use`), `normalizeSourceMap` (transforms source map formats for webpack compatibility), `resolveFilename` (wrapper for webpack's resolver), and `urlResolver` (modifies Stylus's `url()` handling to preserve relative paths). These utilities are self-contained (only depend on `path`, `util`, and internal Stylus APIs) and could be extracted for use in other build tool integrations or standalone preprocessing scripts.

file: src/utils.js ↗ | tags: #custom-evaluator #dependency-resolution #import-resolver #url-resolver
Last analyzed: 2026-09-22 22:20:03.581700
Next check: 2026-09-29 22:20:03.576475
$ submit: