This Heft plugin generates TypeScript .d.ts typings for static asset files, enabling type-safe
import statements for non-TypeScript files. It provides two task plugins:
resource-assets-plugin - Generates .d.ts typings for resource files such as images (.png,
.jpg, .svg, etc.) and fonts. These are opaque binary blobs whose content is not meaningful to
JavaScript; the generated typing simply exports a default string representing the asset URL
(e.g. as resolved by a bundler's asset loader).
source-assets-plugin - Generates .d.ts typings and JavaScript module output for source
files (.html, .css, .txt, .md, etc.) whose textual content is consumed at runtime. The
generated JS modules read the file and re-export its content as a default string, making these
assets importable as ES modules.
The terminology follows the webpack convention
where resource assets are emitted as separate files referenced by URL, while source assets are
inlined as strings.
Both plugins support incremental and watch-mode builds.
Setup
Add the plugin as a devDependency of your project:
Both plugins support two configuration modes via the configType option:
Inline mode (configType: "inline")
Provide configuration directly in heft.json under options.config:
resource-assets-plugin inline config
Option
Type
Default
Description
fileExtensions
string[]
-
(required) File extensions to generate typings for.
generatedTsFolders
string[]
["temp/static-asset-ts"]
Folders where generated .d.ts files are written. The first entry should be listed in rootDirs so TypeScript can resolve the asset imports during type-checking. Additional entries are typically your project's published typings folder(s).
sourceFolderPath
string
"src"
Source folder to scan for asset files.
source-assets-plugin inline config
Includes all the above, plus:
Option
Type
Default
Description
cjsOutputFolders
string[]
-
(required) Output folders for generated CommonJS .js modules.
esmOutputFolders
string[]
[]
Output folders for generated ESM .js modules.
File mode (configType: "file")
Load configuration from a riggable JSON config file in the project's config/ folder:
Option
Type
Description
configFileName
string
(required) Name of the JSON config file in the config/ folder.
The config file supports the same properties as inline mode (see tables above). Config files
can be provided by a rig, making file mode ideal for shared build configurations.
Links
CHANGELOG.md - Find
out what's new in the latest version
@rushstack/heft - Heft is a config-driven toolchain that invokes popular tools such as TypeScript, ESLint, Jest, Webpack, and API Extractor.
Heft is part of the Rush Stack family of projects.