Blazor.LoveJS.Generators 1.0.5

dotnet add package Blazor.LoveJS.Generators --version 1.0.5
                    
NuGet\Install-Package Blazor.LoveJS.Generators -Version 1.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Blazor.LoveJS.Generators" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Blazor.LoveJS.Generators" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="Blazor.LoveJS.Generators" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Blazor.LoveJS.Generators --version 1.0.5
                    
#r "nuget: Blazor.LoveJS.Generators, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Blazor.LoveJS.Generators@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Blazor.LoveJS.Generators&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Blazor.LoveJS.Generators&version=1.0.5
                    
Install as a Cake Tool

Blazor.LoveJS

Blazor.LoveJS makes working with JavaScript in Blazor easier by allowing you to define JavaScript code directly inside Razor components.

This approach keeps everything in one place, simplifying interactions and making it easier to manage JavaScript modules using a Script component reference.

Blazor.LoveJS is particularly useful for small components or quick prototypes, where keeping JavaScript close to the usage improves readability and development speed.

For larger components, it's still best to store JavaScript in separate files for better maintainability.

Example Usage

@using Blazor.LoveJS;

<div id="test" />

<Script @ref="_scriptRef">    
    /* Function have to be exported */
    export function run(message) => {
        document.getElementById("test").innerText = message;
    };
</Script>

@code {
    private Script _scriptRef = null!;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);

        if (firstRender)
        {
            await _scriptRef.InvokeVoidAsync("run", "testMessage");
        }
    }
}

Getting Started

Install the following NuGet packages:

  • Blazor.LoveJS
  • Blazor.LoveJS.Generators

Important: Add the following line to your .csproj file:

<PropertyGroup>
    
    <UseRazorSourceGenerator>false</UseRazorSourceGenerator>
</PropertyGroup>

After compilation, the generator will detect all Script component usages and generate the corresponding JavaScript files to wwwroot/blazorLoveJS/.. .

Managing Output Files

You can control the output file names using the GlobalBundle and BundleName parameters.

The Script component will automatically determine how to properly import these files (e.g., loading them from _content/ or directly from wwwroot).

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 211 5/28/2025
1.0.4 178 3/27/2025
1.0.3 176 3/27/2025
1.0.0 173 3/27/2025