Skip to content

[webpack5-module-minifier-plugin] Inline short license comments - #6167

Merged
Ian Clanton-Thuon (iclanton) merged 2 commits into
microsoft:mainfrom
iclanton:inline-short-licenses
Oct 26, 2026
Merged

Ian Clanton-Thuon (iclanton) merged 2 commits into
microsoft:mainfrom
iclanton:inline-short-licenses

Conversation

@iclanton

Copy link
Copy Markdown
Member

Summary

A JavaScript chunk's license-reference banner can be larger than the complete license text it points to. Add an opt-in inlineShortLicenses option to ModuleMinifierPlugin so short notices can stay in the JavaScript without emitting a companion .LICENSE.txt asset.

new ModuleMinifierPlugin({
  minifier,
  inlineShortLicenses: true
});

Details

  • Default the option to false, retaining the existing external-license policy.
  • Compare the complete, deduplicated license text with the actual reference banner in UTF-8 bytes, including comment delimiters and newlines. Equal-size and longer notices remain external.
  • Make the decision before calling emitAsset, rather than emitting a license asset and removing it in a later processing pass.
  • Feed the chosen banner or inline notice through existing asset rehydration so source maps and module-position metadata account for its length.
  • Preserve license banners for chunks containing only inlined modules. The previous no-placeholder path returned the asset source unchanged and dropped the banner, including external-license references.
  • Include the new option in the existing configuration hash and increment the code-generation revision for the corrected banner behavior.
  • Update the package README, generated API report, and minor change file. This change is limited to the webpack 5 plugin.

How it was tested

  • node common/scripts/install-run-rush.js build --to @rushstack/webpack5-module-minifier-plugin
  • node common/scripts/install-run-rush.js test --to @rushstack/webpack5-module-minifier-plugin
  • All 23 plugin tests pass, including 16 new real-webpack cases covering omitted/disabled defaults, UTF-8 size boundaries, Unicode, deduplication, multiple notices, line/block comments, empty notices, nested content-hashed filenames, entry/async chunks, source maps, and module-position metadata.
  • Temporarily changing the strict comparison to allow equal-byte notices to inline caused the boundary regression test to fail; the original implementation was restored and the suite passed.

Add an opt-in inlineShortLicenses option that compares complete deduplicated notices with the reference banner in UTF-8 bytes before emitting a companion asset. Keep equal-size and larger notices external.

Preserve license banners for chunks containing only inlined modules, and bump the code-generation revision to invalidate affected hashes. Cover defaults, byte boundaries, Unicode, async chunks, source maps and module positions with real webpack builds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use explicit inline/external branches with a single return path, and format inlineShortLicenses as code in the change log.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@iclanton
Ian Clanton-Thuon (iclanton) merged commit 8a50cec into microsoft:main Oct 26, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from Needs triage to Closed in Bug Triage Oct 26, 2026
@iclanton
Ian Clanton-Thuon (iclanton) deleted the inline-short-licenses branch October 26, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

2 participants