Skip to content
This repository was archived by the owner on Sep 3, 2026. It is now read-only.

feat: deprecate the loader in favor of a plugin - #190

Merged
alexander-akait merged 5 commits into
mainfrom
claude/exports-loader-deprecation-0b3zd9
Sep 3, 2026
Merged

feat: deprecate the loader in favor of a plugin#190
alexander-akait merged 5 commits into
mainfrom
claude/exports-loader-deprecation-0b3zd9

Conversation

@alexander-akait

Copy link
Copy Markdown
Member

Summary

What this loader does — appending exports to a file that has none — is a few lines of plugin over webpack's public NormalModule processResult hook, so it does not need a package. This deprecates the loader and hands users the replacement.

  • The loader warns once per rule with the exact code it appends for that rule's options (module.exports = Foo;, export { Foo };, …) and a link to the recipe, so the migration needs no working out.
  • The README's new Deprecation section carries the whole plugin, about twenty lines.
  • The link points at webpack's examples/add-exports, added in docs(examples): add an example that adds exports to a module that has none webpack#21947 — that PR should land first, or the link 404s until it does.

Two things follow from webpack parsing the appended code itself, and both are improvements over the loader: the exports are the module's own, so they take part in tree shaking, mangling, const inlining and scope hoisting; and appending an export is what makes a file an ES module, so there is no type to choose.

What kind of change does this PR introduce?

feat — a deprecation warning is new user-visible behavior.

Did you add tests for your changes?

Yes, test/deprecation.test.js: the warning is emitted, carries the generated code and the link, and is deduplicated to one per rule rather than one per module. Every previously empty warnings snapshot in test/__snapshots__/loader.test.js.snap now carries the warning — that is the whole of the snapshot churn in this PR.

Does this PR introduce a breaking change?

No. The loader keeps working exactly as before; it only warns. ignoreWarnings silences it for anyone not ready to migrate.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

Documented here in the README. If webpack.js.org's Shimming guide links this loader, it should point at the example instead.

Use of AI

Claude Code wrote the change. The plugin in the README is not a sketch — it was run against a real webpack build, where it produced a CommonJs module for a script and a genuine ES module for a vendored file, with PI const-inlined and the source map still naming the original files. Two details in it come from that testing: the preparsed AST must be dropped or webpack parses it instead of the appended code, and the incoming source map can be passed through unchanged because appending never moves what came before it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tj4FVR7z3fkmwde9nqVVyc


Generated by Claude Code

webpack adds exports itself since v5.111.0, through
`module.parser.javascript.exports`. On a webpack that has the option the
loader now warns once per rule and prints the value to replace it with,
computed from the loader's own options; on older webpack it stays silent,
since there is nothing to migrate to. The README gets a deprecation notice
and a migration table.
The core option became a map of export name to expression, so the warning
computes that from the loader's own options — including the
`type: "javascript/esm"` line a script needs for ES module exports — and the
migration table follows.
What the loader does — appending exports to a file that has none — is a few
lines of plugin over webpack's public `NormalModule` `processResult` hook, so
it does not need a package. The loader now warns once per rule with the exact
code it appends and a link to webpack's add-exports example, and the README
carries the whole recipe.
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9c30dc2) to head (89e4289).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #190   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          123       139   +16     
  Branches        53        56    +3     
=========================================
+ Hits           123       139   +16     

☔ 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 fac86df into main Sep 3, 2026
19 checks passed
@alexander-akait
alexander-akait deleted the claude/exports-loader-deprecation-0b3zd9 branch September 3, 2026 20:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant