Skip to content

docs: use the built-in CSS support of webpack in examples - #475

Merged
alexander-akait merged 1 commit into
mainfrom
claude/webpack-css-examples-tests-giu3c2
Aug 29, 2026
Merged

docs: use the built-in CSS support of webpack in examples#475
alexander-akait merged 1 commit into
mainfrom
claude/webpack-css-examples-tests-giu3c2

Conversation

@alexander-akait

Copy link
Copy Markdown
Member

Updates the documentation examples to use the built-in CSS support of webpack (the css/auto module type together with experiments.css) instead of chaining the loader with css-loader and style-loader, in line with what less-loader does, and covers the same setup with tests.

Documentation

Every webpack.config.js example now looks like this:

module.exports = {
  module: {
    rules: [
      {
        test: /\.styl$/i,
        type: "css/auto",
        use: ["stylus-loader"],
      },
    ],
  },
  experiments: {
    css: true,
  },
};

This covers "Getting Started" (with a note that experiments.css has to be enabled) and all option examples (stylusOptions object/function, sourceMap, webpackImporter, additionalData string/sync/async, implementation), as well as the examples section (normal usage, source maps, nib, importing JSON files, Stylus resolver).

Additionally:

  • Added a "Using css-loader and style-loader" section — the built-in CSS support is not mandatory, so chaining with css-loader and style-loader is still documented as the alternative.
  • Added a "CSS modules" section — with type: "css/auto", *.module.styl files are treated as CSS modules.
  • Updated "In production" and "Extracting style sheets": the built-in CSS support extracts style sheets out of the box, output.cssFilename/output.cssChunkFilename configure the file names, and the MiniCssExtractPlugin is only needed when chaining with css-loader.

Tests

  • Added test/helpers/getCssCompiler.js, which builds with experiments.css enabled and the css/auto module type, i.e. the configuration from the documentation.
  • Added test/builtin-css.test.js, which checks the emitted CSS asset for a basic file, @import, url() (the referenced image is emitted as an asset), CSS modules (exported class names and the generated CSS), source maps (the .map asset and its sources) and a broken file.
  • The test runner now only picks up test/*.test.js, otherwise the new JavaScript fixture is treated as a test file. The glob is passed as the last argument in test and test:coverage, because Node stops parsing its own flags after the first positional argument (npm run test:coverage still writes coverage.lcov).

npm test (lint + 153 tests) passes.


Generated by Claude Code

Rewrite the `README.md` examples to use webpack's built-in CSS support
(the `css/auto` module type plus `experiments.css`) instead of chaining
the loader with `css-loader` and `style-loader`, add sections about
`css-loader`/`style-loader` chaining and CSS modules, and update the
production/extracting notes accordingly.

Cover the same setup with tests: a new `getCssCompiler` helper builds
with `experiments.css` enabled and the new `test/builtin-css.test.js`
checks the emitted CSS, `@import`, `url()`, CSS modules, source maps
and errors.

The test runner now only picks up `test/*.test.js`, so JavaScript
fixtures are not treated as test files.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R5LK1NnJYsgthMpP5iqZ3C
@codecov

codecov Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.21%. Comparing base (111ddd3) to head (12233ca).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #475   +/-   ##
=======================================
  Coverage   96.21%   96.21%           
=======================================
  Files           2        2           
  Lines        1269     1269           
=======================================
  Hits         1221     1221           
  Misses         48       48           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexander-akait
alexander-akait merged commit 936ff82 into main Aug 29, 2026
16 checks passed
@alexander-akait
alexander-akait deleted the claude/webpack-css-examples-tests-giu3c2 branch August 29, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant