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
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
What this loader does — appending exports to a file that has none — is a few lines of plugin over webpack's public
NormalModuleprocessResulthook, so it does not need a package. This deprecates the loader and hands users the replacement.module.exports = Foo;,export { Foo };, …) and a link to the recipe, so the migration needs no working out.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
exportis what makes a file an ES module, so there is notypeto 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 emptywarningssnapshot intest/__snapshots__/loader.test.js.snapnow 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.
ignoreWarningssilences 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
PIconst-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