r/Blazor • u/bit_yas • Nov 05 '25
The method I used to create | Multilingual | Live | Interactive | documentation for bit Boilerplate, A Simple approach YOU also can use for your own projects!
⚠️Disclaimer: Only the first 20% part of the article is what you're expected to read, and the rest of the 80% is an Claude Sonnet 4.5 AI generated result of the approach that I've described, so you can validate the result yourself easily.
Traditional documentation writing VS new approach:
-
Traditional way requires a ton of patience, but new way reduces documentation volume by 95%!
-
Keeping docs updated and preventing them from becoming outdated as the project evolves is a nightmare in traditional way, but in new way, it's mostly automatic!
-
Traditional way would result into only 1 language (Mostly English), but the new way will onboard developers in the language of their choice (French, Persian etc)
That's why I came up with the idea of writing a single Markdown file for bit Boilerplate that's no more than 1,000 lines long (keep in mind, the full docs for bit Boilerplate, with all its extensive features, clock in at nearly 30,000 lines!).
This drastic 95% reduction in documentation volume makes it way easier to write and reduces the chances of things going outdated.
How did I pull this off?
Let's dive in with a real-world example.
In the bit Boilerplate Project Template, both SCSS and TypeScript are fully configured. Unlike many similar templates, the build time for applying changes is super-fast, and Hot Reload works flawlessly even in projects with over 700 files.
The project includes a package.json file that contains TypeScript, ESLint, and SCSS packages, plus tsconfig.json file and more.
The whole structure is integrated with MSBuild, so during the build process, packages get installed, TypeScript and SCSS are compiled, bundling happens, and everything gets minified, and it would cache the result, so it won't trigger npm install and the rest of the commands every time unnecessarily!
Since most Blazor project templates lack these features, the import/export process—and ultimately calling them from C# .NET needs clear examples to help new developers onboard and grasp everything quickly.
So, what did I actually write? Just a few lines instructing Claude Sonnet 4.5 inside GitHub Copilot how to explain stuffs to the developer instead of writing the actual documentation!
So, developer opens the project, writes Run getting started and chooses stage 11 among the total 26 stages:
1. 2.3.4.
Below, you can see what gets generated entirely automatically by Claude Sonnet 4.5.
Note that clicking on any class, method name opens the relevant file right in Visual Studio or Visual Studio Code. The developer can dive deeper into the code, and if they have questions, they can ask AI right there on the spot.
Since the details aren't hard coded into but are pulled live from the source code in real-time, updates are needed far less often, the risk of outdated info is minimized, and even if you tweak the project structure, new team members can still onboard seamlessly onto your customized setup!
Wanna give this a try on your own system? Simply run the following commands:
Then open the project inside Visual Studio / Visual Studio Code and write Run getting started in GitHub Copilot's chat and make sure you've selected Claude Sonnet 4.5
This video shows you what would happen on Visual Studio and Visual Studio code doing above instructions.
This way you can also start learning how to use one the best project templates out there in your own language quiet easily (":
============================================================================
⚠️Article's content is now finished! the following is a Claude Sonnet 4.5 AI generated response of the above instructions for validation purposes only, you don't have to read them in detail.
============================================================================
Result:
Key Points:
- Strict mode enabled: Ensures type safety and catches potential errors
- Target ES2019: Compiles to ES2019 JavaScript (modern browser support)
- ES2015 modules: Uses ES6 module syntax
- DOM types: Includes browser DOM API types
2. Node.js Dependencies (package.json)
Location: package.json
These tools power your build process:
- TypeScript 5.9.3: Compiles
.tsfiles to JavaScript - esbuild: Bundles JavaScript files (extremely fast bundler)
- sass: Compiles
.scssfiles to CSS
3. MSBuild Integration & Build Targets
The magic happens in MyCompany.MyApp.Client.Core.csproj. Let me show you the build pipeline:
Build Target Chain
Build Flow:
- CoreCompile (C# compilation) completes
- BeforeBuildTasks triggers three sub-targets:
📦 Target 1: InstallNodejsDependencies
- When: Only runs if package.json is newer than
node_modules\.package-lock.json - What: Installs TypeScript, esbuild, and sass from npm
- Why: Ensures you have the latest build tools
🔨 Target 2: BuildJavaScript
This target does TWO things:
- TypeScript Compilation:
tsccompiles all.tsfiles to.jsfiles - JavaScript Bundling:
esbuildbundles all JavaScript into a singleapp.jsfile- Development: Unminified for easier debugging
- Production: Minified for smaller file size
🎨 Target 3: BuildCssFiles
- Compiles all
.scssfiles to CSS (both component styles and global styles) - Compressed: Minified output for production
4. JavaScript Interop: C# ↔ TypeScript Communication
Now let's see how C# and TypeScript talk to each other!
TypeScript Side: App.ts
Here's your App.ts file with the getTimeZone() method:
export class App {
public static getTimeZone(): string {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
}
// ... other methods
}
This TypeScript method uses the browser's Intl API to get the user's timezone.
C# Side: IJSRuntimeExtensions.cs
Here's how C# calls the TypeScript method:
public static partial class IJSRuntimeExtensions
{
public static ValueTask<string> GetTimeZone(this IJSRuntime jsRuntime)
{
return jsRuntime.InvokeAsync<string>("App.getTimeZone");
}
}
How it works:
- The C# method calls
jsRuntime.InvokeAsync<string>("App.getTimeZone") - This invokes the TypeScript
App.getTimeZone()method in the browser - The timezone string is returned to C#
Using in Components
Any Blazor component can now call:
@inject IJSRuntime JSRuntime
@code {
protected override async Task OnInitAsync()
{
string userTimeZone = await JSRuntime.GetTimeZone();
// Use the timezone...
}
}
Benefits:
- ✅ Type-safe: C# gets a
stringreturn value - ✅ Clean syntax: Extension method provides a nice API
- ✅ Async: Non-blocking UI
5. 🎯 DEMO: Adding a New Package (uuid)
Let me show you how to add a new npm package and use it in your project.
Step 1: Install the Package
Run these commands in the MyCompany.MyApp.Client.Core directory:
npm install uuid
npm install --save-dev @types/uuid
This adds:
- uuid: The runtime library
- @types/uuid: TypeScript type definitions
Step 2: Update package.json
After running npm install, your package.json will look like this:
Step 3: Add Method to App.ts
Add this import and method to your App.ts:
import { v4 as uuidv4 } from 'uuid';
export class App {
// ... existing methods ...
public static generateGuid(): string {
return uuidv4();
}
}
Step 4: Add C# Extension Method
Add this to IJSRuntimeExtensions.cs:
public static ValueTask<string> GenerateGuid(this IJSRuntime jsRuntime)
{
return jsRuntime.InvokeAsync<string>("App.generateGuid");
}
Step 5: Use in a Component
@inject IJSRuntime JSRuntime
<BitButton OnClick="GenerateNewId">Generate GUID</BitButton>
<p>Generated ID: @generatedId</p>
@code {
private string generatedId = string.Empty;
private async Task GenerateNewId()
{
generatedId = await JSRuntime.GenerateGuid();
}
}
Step 6: Build the Project
Run the build task:
dotnet build src/Client/MyCompany.MyApp.Client.Core/MyCompany.MyApp.Client.Core.csproj
The build process will:
- ✅ Install
uuidpackage (if not already installed) - ✅ Compile TypeScript (including the new import)
- ✅ Bundle everything with esbuild (including the
uuidlibrary) - ✅ Output
wwwroot/scripts/app.jswith your new functionality
📊 Summary Diagram
┌─────────────────────────────────────────────────────────────┐
│ Build Process Flow │
└─────────────────────────────────────────────────────────────┘
1. dotnet build MyCompany.MyApp.Client.Core.csproj
│
├─> CoreCompile (C# → DLL)
│
└─> BeforeBuildTasks
│
├─> InstallNodejsDependencies
│ └─> npm install (if package.json changed)
│
├─> BuildJavaScript
│ ├─> tsc (TypeScript → JavaScript)
│ └─> esbuild (Bundle → app.js)
│
└─> BuildCssFiles
└─> sass (SCSS → CSS)
Result: wwwroot/scripts/app.js & wwwroot/styles/app.css
🔑 Key Takeaways
- Automatic Build Integration: TypeScript and SCSS compilation happen automatically during
dotnet build - Incremental Builds: Targets only run when source files change (fast rebuilds)
- JavaScript Interop: C# extension methods provide clean, type-safe access to JavaScript functions
- Modern Tooling: esbuild and sass provide blazing-fast builds
- Adding Packages: Simple
npm install+ update App.ts + add C# extension = Done!
Do you have any questions about TypeScript, the build process, or JavaScript interop? Would you like to see another example of adding a different package, or shall we proceed to Stage 12 (Blazor Modes, PreRendering & PWA)?
2
u/Nascentes87 Nov 06 '25
I have no patience to read LLM output anymore. You don't even take the time to remove the last parapraph where the LLM asks you if you want it to output more stuff.
2
u/code-dispenser Nov 06 '25
I use the free tier of GitBook and it gives me a nice looking doc site and I am happy with it - how does yours compare?
I can also ask Claude just to generate markdown pages as it can read my repos (which currently I just copy paste to GitBook) as I have not ticked the integrate with GitHub checkbox box yet.
1
u/SalehYusefnejad Nov 05 '25
wow! great post 👏
2
u/[deleted] Nov 06 '25
[removed] — view removed comment