Skip to content

Frontend ​

Introduction ​

DotBlaze renders HTML on the server with Blade templates and Razor views (see Views). For styling and small interactions, the template ships with Tailwind CSS and Alpine.js, the same pairing Laravel's starter kits use.

The template build is intentionally small: the Tailwind CLI compiles your CSS, and Alpine's prebuilt file is copied next to it. Both end up in wwwroot/build. Applications can opt into the Vite facade for a development server and manifest-based production assets.

For interactive pages without writing JavaScript, use live components (Livewire-style components that update over HTTP). Their script is served by DotBlaze itself; add @Live.Scripts() to the layout.

Building Assets ​

Install the npm dependencies once, then build:

shell
npm install
npm run build

The build script in package.json does two things:

  1. Compiles resources/css/app.css with the Tailwind CLI into a minified wwwroot/build/app.css.
  2. Copies node_modules/alpinejs/dist/cdn.min.js to wwwroot/build/alpine.js.

wwwroot/build is ignored by git, so run the build after cloning a project and as part of every deployment.

Watching for Changes ​

While developing, npm run dev runs Tailwind in watch mode and rebuilds app.css whenever a view or the CSS file changes:

shell
npm run dev

Run it in one terminal and dotnet watch in another. npm run dev only rebuilds the CSS; it does not copy Alpine, so run npm run build at least once first.

Tailwind CSS ​

The template uses Tailwind CSS v4, configured in CSS rather than in a JavaScript config file. resources/css/app.css contains:

css
@import "tailwindcss";
@source "../views";

The @source line tells Tailwind to scan your Razor views for class names. If you use Tailwind classes elsewhere (for example in C# code that builds class strings), add another @source line for that directory. Your own CSS goes in the same file, below the import.

Alpine.js ​

Alpine.js is loaded on every page by the layout, so you can add behaviour directly in your markup. The template's welcome page uses it for a counter:

html
<div x-data="{ count: 0 }" class="mt-6">
    <button type="button" class="rounded bg-indigo-600 px-4 py-2 text-white" x-on:click="count++">
        Alpine clicks: <span x-text="count">0</span>
    </button>
</div>

WARNING

Razor treats @ as the start of C# code, so Alpine's @click shorthand must be escaped as @@click in a .cshtml file. The long form, x-on:click, needs no escaping in either Razor or Blade.

Including Assets in Views ​

The layout at resources/views/layouts/app.blade.html includes both files:

html
<link rel="stylesheet" href="~/build/app.css" asp-append-version="true" />
<script defer src="~/build/alpine.js" asp-append-version="true"></script>

asp-append-version="true" is an ASP.NET Core tag helper that appends a hash of the file's contents to the URL (app.css?v=...). Browsers can cache the files for as long as you like, and a new build automatically produces a new URL, much like the versioned file names Laravel's Vite integration generates. The tag helpers are enabled in _ViewImports.cshtml with @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers.

Adding Other JavaScript ​

Any file in wwwroot is served as a static file. To add a script of your own, place it in wwwroot (outside build, which is generated) and reference it from the layout:

html
<script defer src="~/js/app.js" asp-append-version="true"></script>

If you need an npm package other than Alpine, either copy its prebuilt browser file in the build script the same way Alpine is copied, or introduce a bundler of your choice. DotBlaze does not depend on the build tool; it only serves what ends up in wwwroot.

Complete Example: Accessible Disclosure ​

In the Blog template, add this inside the content section of resources/views/home/Index.blade.html:

html
<section x-data="{ open: false }" class="mt-6 rounded border p-4">
    <h2>
        <button type="button" x-on:click="open = !open"
                x-bind:aria-expanded="open" aria-controls="help-details"
                class="rounded bg-indigo-600 px-4 py-2 text-white">
            Show application help
        </button>
    </h2>
    <p id="help-details" x-show="open" style="display: none;">
        Create a post from the Posts page after signing in.
    </p>
</section>

Run npm install, npm run build, and dotblaze serve. Open / and use either mouse or keyboard to toggle the paragraph. Inspect the button: aria-expanded changes with the visible state. This interaction runs entirely in the browser; use a live component when the action needs server-side code.