ESBuild.AspNetCore is a build-time TypeScript bundling package for ASP.NET Core projects powered by esbuild (GitHub). It was inspired by AspNetCore.SassCompiler, with the same goal of making asset compilation work as a NuGet-powered MSBuild integration instead of a separate Node-based toolchain step.
This repository is currently 100% AI-generated code. Because of that, no pull request will be accepted without prior approval from the maintainer. If you want to contribute, open an issue first and wait for confirmation before investing time in a PR.
- Reads configuration exclusively from
esbuild.json - Runs
esbuildduringdotnet buildanddotnet publish - Ships platform-specific
esbuildbinaries inside the NuGet package - Adds generated files back into the ASP.NET Core static file/publish pipeline
- Supports Debug/Release defaults and configuration-specific per-bundle overrides
- It does not read
appsettings.json - It does not require changes to
Program.cs - It does not provide watch mode, hot reload integration, or runtime bundling
- It does not require Node.js or a global
esbuildinstallation
Add the package to an ASP.NET Core project:
dotnet add package ESBuild.AspNetCoreThen create an esbuild.json file in the project root.
esbuild.json
{
"Bundles": [
{
"EntryPoint": "Scripts/site.ts",
"Output": "wwwroot/js/site.js"
}
],
"Configurations": {
"Debug": {
"Defaults": {
"Minify": false,
"Sourcemap": true
}
},
"Release": {
"Defaults": {
"Minify": true,
"Sourcemap": false
}
}
}
}After that, dotnet build will generate wwwroot/js/site.js.
Top-level shape:
{
"Defaults": {},
"Bundles": [],
"Configurations": {}
}Supported default fields:
MinifySourcemapTargetFormatPlatform
Built-in package defaults:
Minify: falseSourcemap: trueTarget: "es2020"Format: "iife"Platform: "browser"
Each bundle supports:
EntryPointOutputOutdirOptionalSplittingMinifySourcemapTargetFormatPlatformExternalDefineAliasLoaderPublicPath
Rules:
- Each bundle must define
EntryPoint - Each bundle must define exactly one of
OutputorOutdir SplittingrequiresOutdirSplittingrequiresFormat: "esm"Optional: trueskips the bundle if the entry point file does not exist
Each configuration can contain:
DefaultsBundles
Configurations.<name>.Defaults overrides root defaults for that build configuration.
Configurations.<name>.Bundles applies per-bundle overrides matched by EntryPoint. Override entries must define EntryPoint, and that EntryPoint must match exactly one root bundle.
This allows Debug and Release to output different files:
{
"Bundles": [
{
"EntryPoint": "Scripts/site.ts",
"Output": "wwwroot/js/site.js"
}
],
"Configurations": {
"Debug": {
"Defaults": {
"Minify": false,
"Sourcemap": true
}
},
"Release": {
"Defaults": {
"Minify": true,
"Sourcemap": false
},
"Bundles": [
{
"EntryPoint": "Scripts/site.ts",
"Output": "wwwroot/js/site.release.js"
}
]
}
}
}{
"Bundles": [
{
"EntryPoint": "Scripts/site.ts",
"Outdir": "wwwroot/js",
"Splitting": true,
"Format": "esm"
}
]
}When splitting is enabled, the package tracks emitted chunk files using esbuild metafile output and persists the discovered output set under obj/ESBuild.AspNetCore.
Effective bundle settings are resolved in this order:
- Package defaults
- Root
Defaults - Root bundle values
- Configuration
Defaults - Configuration-specific bundle override values
If a configuration-specific bundle override specifies Output, it replaces Outdir. If it specifies Outdir, it replaces Output.
The package currently ships vendored esbuild binaries for:
- Windows x64
- Windows arm64
- Linux x64
- Linux arm64
- macOS x64
- macOS arm64
Typical failure cases:
- missing
EntryPoint - missing both
OutputandOutdir - defining both
OutputandOutdir - unsupported
Format - unsupported
Platform Splittingused withoutOutdirSplittingused with a format other thanesm- invalid configuration-specific bundle override matching
Builds fail with explicit error messages for invalid configuration.
- This project is intentionally build-time only
- Configuration comes only from
esbuild.json appsettings.jsonconfiguration is ignored- Generated files are included in normal ASP.NET Core content/publish output
Open an issue before opening a PR. Unapproved pull requests should be assumed likely to be closed without merge, especially while the repository is still stabilizing its AI-generated foundation.