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
<PackageReference Include="Blazor.LoveJS.Generators" Version="1.0.5" />
<PackageVersion Include="Blazor.LoveJS.Generators" Version="1.0.5" />
<PackageReference Include="Blazor.LoveJS.Generators" />
paket add Blazor.LoveJS.Generators --version 1.0.5
#r "nuget: Blazor.LoveJS.Generators, 1.0.5"
#:package Blazor.LoveJS.Generators@1.0.5
#addin nuget:?package=Blazor.LoveJS.Generators&version=1.0.5
#tool nuget:?package=Blazor.LoveJS.Generators&version=1.0.5
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).
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.