npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

piral-blazor

v1.12.3

Published

Plugin for integrating Blazor components in Piral.

Readme

Piral Logo

Piral Blazor · GitHub License npm version tested with vitest Community Chat

This is a plugin that has a peer dependency to blazor. What piral-blazor brings to the table is a set of Pilet API extensions that can be used with piral or piral-core.

The set includes a Blazor (WASM) loader and converter for any component registration, as well as a fromBlazor shortcut together with some Blazor component coming in the Piral.Blazor.Utils NuGet package.

::: warning: Only for Blazor WASM The Blazor integration is for the client-side framework Blazor, also known as Blazor WASM.

If you want to use Blazor Server we recommend using one of the ways of including a server-side rendered application as a pilet. More infos can be found at in our migration tutorial for SSR applications. :::

By default, these API extensions are not integrated in piral, so you'd need to add them to your Piral instance.

Documentation

As Blazor is quite a special technology (since its based on WebAssembly) there are some very special things to follow for integration. The result, however, could be worth it. As Piral gives you here a truly unique and wonderful way of building your application - modular, distributed, and with the fastest possible Blazor startup time!

Important: We recommend building pilets for piral-blazor exclusively with the official template.

The template can be installed using the dotnet CLI:

dotnet new -i Piral.Blazor.Template

Then you can always apply the template in an empty folder:

dotnet new blazorpilet --piralInstance my-app-shell

where my-app-shell should refer to the name of the NPM package of your app shell. The --npmRegistry option is there, to cover cases where your app shell is not hosted in the standard NPM registry.

Exposing components looks like:

@attribute [PiralExtension("sample-page")]

<div>
    <p>
        Current count: @counter
    </p>
    <p>
        <button @onclick="Increment">Increment</button>
    </p>
</div>

@code {
    int counter = 0;

    void Increment()
    {
        counter++;
    }
}

For more details visit the Piral.Blazor repository.

Architecture

Blazor with Piral works from two sides. We have the app shell's side and the side of the micro frontends. This package allows to connect both sides, by placing a set of shared functionality in the app shell.

Architecture Diagram

The diagram has the following pieces:

  1. Your app shell using piral, which needs to reference the piral-blazor plugin. Effectively, this will use the blazor package at build-time to include the Blazor libraries. Additionally, it uses Piral.Blazor.Core to be able to reference the defined Blazor components.
  2. The TypeScript file in your Blazor pilets. That file will export the setup function to define which Blazor components to register/use in your app shell.
  3. The Blazor code in your Blazor pilets using the shared library Piral.Blazor.Utils for some convenience functions. This code will define all the Blazor components that can be registered/used in the pilet.

Naturally, you can add other dependencies to your Blazor pilet, too. These can be other npm packages for extending the JS part. Usually, however, you will add more NuGet packages to enhance your Blazor code.

This Munich .NET Meetup video recording gives you a lot of details on the used architecture.

API

The following functions are brought to the Pilet API.

defineBlazorReferences()

Adds the URLs to additional DLLs that need to be referenced for obtaining the Blazor components. At best this uses require.resolve to get the URL from the bundler.

When you use the blazorpilet template you don't need to fill/use this. It is automatically used and filled with generated code. Only touch this one if you know what you are doing.

fromBlazor()

Transforms a standard Blazor component into a component that can be used in Piral, essentially wrapping it with a reference to the corresponding converter.

There is only a single argument, which refers to the name of the exposed Blazor component.

Usage

::: summary: Modern Use (recommended)

Note: If you use the .NET template (and specifically the Piral.Blazor.Tools package) then the whole JavaScript code will be generated for you. There is nothing you will need to do - even though you can also manually extend the generated JavaScript module.

The recommended way is to use piral-blazor from your pilets. In this case, no registration in the Piral instance is required.

Example use:

import { PiletApi } from '<name-of-piral-instance>';
import { defineBlazorReferences, fromBlazor } from 'piral-blazor/convert';

export function setup(piral: PiletApi) {
  defineBlazorReferences([
    require.resolve('./My.Dependency.dll'),
    require.resolve('./My.Components.dll'),
  ])
  piral.registerPage('/sample', fromBlazor('sample-page'));
}

In this case, you'll also have to install the blazor package. piral-blazor will use this under the hood to access the Blazor libraries.

To maximize compatibility, the major and minor version of the blazor package should correspond to the major and minor version of .NET Blazor you want to use (e.g., [email protected] will resolve to the outdated .NET Blazor 3.2 release train - more recent ones look like [email protected]). It should be noted that the patch level is not aligned. If a specific patch level is desired, consult the blazor package documentation.

Within Blazor components the Extension component referenced from Piral.Blazor.Utils, e.g.,

<Extension name="name-of-extension" />

:::

::: summary: Legacy Use

For backwards compatibility, you can also install piral-blazor in your Piral instance.

Using Blazor with Piral is as simple as installing the piral-blazor and blazor packages.

import { createBlazorApi } from 'piral-blazor';

The integration looks like:

const instance = createInstance({
  // important part
  plugins: [createBlazorApi()],
  // ...
});

piral-blazor will use blazor under the hood to access the Blazor libraries.

To maximize compatibility, the major and minor version of the blazor package should correspond to the major and minor version of .NET Blazor you want to use (e.g., [email protected] will resolve to the .NET Blazor 3.2 release train). It should be noted that the patch level is not aligned. If a specific patch level is desired, consult the blazor package documentation.

For setting up localization you can supply options such as initialLanguage and onLanguageChange to the createBlazorApi call. While the former is used to set the initial language, the latter can be used to change the language later on. By default, onLanguageChange will be configured to listen to the select-language event emitted from Piral. This event is emitted (among others) by piral-translate, i.e., if you use this plugin it will just work.

Otherwise, you can either emit the event yourself (transporting an object with currentLanguage set to the desired language), or use onLanguageChange to wire it to whatever event source / emitter you'd like.

Ultimately, you can also call the SetLanguage in Piral.Blazor.Core from JavaScript like this:

window.DotNet.invokeMethodAsync('Piral.Blazor.Core', 'SetLanguage', language);

Furthermore, it is possible to configure the (initial) log level via the logLevel option:

const instance = createInstance({
  // important part
  plugins: [createBlazorApi({
    logLevel: 1, // everything except trace
  })],
  // ...
});

The levels range from 0 (incl. trace) to 6 (nothing will be logged).

:::

Events

The piral-blazor integration emits some events at the global object (window):

  • loading-blazor-core when the loading of (core) Blazor resources starts
  • loaded-blazor-core when the loading of (core) Blazor resources ends
  • loading-blazor-pilet when the loading of a Blazor pilet / its resources starts (detail contains the pilet's metadata)
  • loaded-blazor-pilet when the loading of a Blazor pilet / its resources ends (detail contains the pilet's metadata)

You can receive these events using, e.g.:

window.addEventListener('loaded-blazor-pilet', (ev) => {
  // your code here - could use:
  // ev.detail.name --> name of the pilet
});

License

Piral is released using the MIT license. For more information see the license file.