MapBlazor Architecture, Part 1: Goals, Project Layout and the Build Pipeline
- Get link
- X
- Other Apps
Goals
- No JavaScript for consumers. Everything a page needs is a component parameter or an injected service.
- Many maps per page. Each map is identified by a type, so services and state never mix maps up.
- The SDK stays the source of truth. Live ArcGIS objects never cross into .NET. .NET sends intentions and receives summaries.
- Works in every render mode. Server, WebAssembly and Auto all share one code path.
- Ships as one NuGet package, including the SDK's own assets.
Solution layout
| Folder | Holds |
|---|---|
Components/ |
MapView<TMap>, the only Razor component |
Services/ |
Layer, basemap, extent, zoom, draw, selection, highlight and popup services |
Store/ |
Fluxor features: map view state (keyed by map type) and layer state |
JsInterop/Data |
Internal DTO records with explicit JSON names |
JsInterop/Modules |
DotNetObjectReference callback receivers |
Data/ |
The public model: geometry, layer descriptions, symbols, renderers |
Scripts/ |
TypeScript: bootstrap, map builder, layers, draw, select, widgets |
wwwroot/ |
Build output, served as static web assets at _content/MapBlazor/... |
The JavaScript build
The TypeScript side is a normal npm project inside the RCL:
{
"type": "module",
"dependencies": {
"@arcgis/core": "^5.0.0",
"@arcgis/map-components": "^5.0.0",
"@esri/calcite-components": "^5.0.0"
},
"devDependencies": { "esbuild": "^0.25.0", "typescript": "^5.9.0" }
}
esbuild bundles two entry points:
| Entry | Role |
|---|---|
core/bootstrap.ts |
Tiny, with no SDK imports. It receives configuration, seeds esriConfig, then loads everything else (Part 2) |
mapBlazor.ts |
The facade: re-exports every feature function (Part 3) |
// esbuild.config.js
await esbuild.build({
entryPoints: ["Scripts/mapBlazor.ts", "Scripts/core/bootstrap.ts"],
bundle: true, format: "esm", splitting: true, target: "es2020",
outdir: "wwwroot/js", sourcemap: true, minify: isRelease,
});
Code splitting matters: the SDK is large, and features are only loaded when first used.
SDK assets (workers, fonts, localization files, Calcite icons) are copied from node_modules into wwwroot/assets. The SDK is then pointed at them with assetsPath. Write a small version stamp next to them, so the copy step runs only when the SDK version changes.
Wiring npm into MSBuild
<Target Name="BuildScripts" BeforeTargets="PreBuildEvent" Condition="'$(SkipScriptBuild)' != 'true'">
<Exec Command="npm ci" Condition="!Exists('node_modules/.package-lock.json')" />
<Exec Command="node esbuild.config.js $(ScriptBuildArgs)" />
</Target>
- Call
nodedirectly and rely on exit codes. Searching the output for the word "Error" is fragile. - Provide an opt-out property (
SkipScriptBuild) for CI legs that build the JS separately. - Git-ignore the generated
wwwroot/jsandwwwroot/assets. The package build produces them.
Versioning
Encode both versions in the package version: 1.4.0-sdk5.0.18 means library 1.4.0 built against SDK 5.0.18. Consumers can then see which SDK they're getting, and upgrading the SDK is a visible version bump.
Keep the README, the package description and the actual package-lock.json in step. Generate the description from the lock file in CI if you can.
- Get link
- X
- Other Apps
Comments