Introduce a Heft plugin for generating types for static assets.#5666
Merged
iclanton merged 17 commits intomicrosoft:mainfrom Feb 24, 2026
Merged
Introduce a Heft plugin for generating types for static assets.#5666iclanton merged 17 commits intomicrosoft:mainfrom
iclanton merged 17 commits intomicrosoft:mainfrom
Conversation
dmichon-msft
approved these changes
Feb 23, 2026
Contributor
dmichon-msft
left a comment
There was a problem hiding this comment.
Works, but some improvements to be had.
heft-plugins/heft-static-asset-typings-plugin/src/BinaryAssetsPlugin.ts
Outdated
Show resolved
Hide resolved
heft-plugins/heft-static-asset-typings-plugin/src/StaticAssetTypingsGenerator.ts
Show resolved
Hide resolved
heft-plugins/heft-static-asset-typings-plugin/src/StaticAssetTypingsGenerator.ts
Show resolved
Hide resolved
heft-plugins/heft-static-asset-typings-plugin/src/TextAssetsPlugin.ts
Outdated
Show resolved
Hide resolved
heft-plugins/heft-static-asset-typings-plugin/src/TextAssetsPlugin.ts
Outdated
Show resolved
Hide resolved
heft-plugins/heft-static-asset-typings-plugin/src/TextAssetsPlugin.ts
Outdated
Show resolved
Hide resolved
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Introduces
@rushstack/heft-static-asset-typings-plugin, a Heft plugin that generates TypeScript.d.tstypings for static asset files. The plugin provides two task plugins:binary-assets-plugin— Generates.d.tstypings for binary files (images, fonts, etc.), enabling type-safeimportstatements withoutrequire()orallowArbitraryExtensions.text-assets-plugin— Generates.d.tstypings and JavaScript module output for text-based files (.html,.txt, etc.), making text content directly importable as ES modules.Both plugins support incremental and watch-mode builds.
Details
The plugin uses
@rushstack/typings-generatorto produce.d.tsdeclarations of the formdeclare const content: string; export default content;for each matched asset file. Matching is configured by file extension.Binary assets plugin supports two configuration modes:
config/Text assets plugin additionally emits CommonJS and/or ESM
.jsmodules alongside the typings, with SHA1-based content hashing for incremental rebuilds.The plugin is integrated into:
heft-web-rig(both app and library profiles) for image file typingsheft-webpack5-everything-test,heft-webpack4-everything-test,heft-rspack-everything-test— binary-assets-plugin with.pngfilesheft-node-everything-test— text-assets-plugin with.htmlfilesThe
heft-typescript-composite-testproject is excluded because TypeScript'srootDirs(needed for generated typings resolution) is incompatible with composite project references.The
heft-webpack4-everything-testtsconfig was updated to enableesModuleInteropso thatimport image from './image.png'compiles correctly with the Jest string-mock transform.How it was tested
rush build --to @rushstack/heft-static-asset-typings-pluginrush build --to heft-webpack5-everything-test --to heft-webpack4-everything-test --to heft-rspack-everything-test --to heft-node-everything-testheft-webpack4-everything-test,heft-webpack5-everything-test, andheft-node-everything-test— all pass.d.tstypings intemp/image-typings/, CJS modules inlib-commonjs/, ESM modules inlib-esm/