AspNetCoreJsModules 0.1.1

dotnet add package AspNetCoreJsModules --version 0.1.1                
NuGet\Install-Package AspNetCoreJsModules -Version 0.1.1                
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="AspNetCoreJsModules" Version="0.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspNetCoreJsModules --version 0.1.1                
#r "nuget: AspNetCoreJsModules, 0.1.1"                
#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.
// Install AspNetCoreJsModules as a Cake Addin
#addin nuget:?package=AspNetCoreJsModules&version=0.1.1

// Install AspNetCoreJsModules as a Cake Tool
#tool nuget:?package=AspNetCoreJsModules&version=0.1.1                

AspNetCoreJsModules

ASP.NET Core MVC Tag helpers for working with JavaScript modules and import maps.

ci Nuget (with prereleases)

Installation

1. Install NuGet package

Install the AspNetCoreJsModules NuGet package:

Install-Package AspNetCoreJsModules

Or via the .NET Core command line interface:

dotnet add package AspNetCoreJsModules

2. Configure your ASP.NET Core application

Add services to your application's Startup class:

using AspNetCoreJsModules;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddJsModules();
    }
}

3. Register tag helpers

In your _ViewImports.cshtml file:

@addTagHelper *, AspNetCoreJsModules

Working with modules and import maps

The <js-modules> tag helper generates an import map was as script type="module" and link rel="modulepreload" elements for every <js-import> on the page. Each <js-import> requires a name and path attribute. The path attribute can reference a local or remote file. For local files, you can set append-version="true" to have ASP.NET Core append a version hash.

<js-modules>
  <js-import name="@@hotwired/stimulus" path="https://unpkg.com/@@hotwired/stimulus@3.0.1/dist/stimulus.js" />
  <js-import name="MyModule" path="~/modules/my-module.js" append-version="true" />
</js-modules>

Renders:

<script type="importmap">
{
  "imports": {
    "@hotwired/stimulus": "https://unpkg.com/@hotwired/stimulus@3.0.1/dist/stimulus.js",
    "MyModule": "/modules/my-module.js?v=NDJARtKDTcKIE8ytjKwNo_-SSH8LKz_chEuHcASozBk"
  }
}
</script>
<script src="https://unpkg.com/@hotwired/stimulus@3.0.1/dist/stimulus.js" type="module"></script>
<script src="/modules/my-module.js?v=NDJARtKDTcKIE8ytjKwNo_-SSH8LKz_chEuHcASozBk" type="module"></script>
<link href="https://unpkg.com/@hotwired/stimulus@3.0.1/dist/stimulus.js" rel="modulepreload" />
<link href="/modules/my-module.js?v=NDJARtKDTcKIE8ytjKwNo_-SSH8LKz_chEuHcASozBk" rel="modulepreload" />

Adding modules from outside tag helpers

You can also add modules from code:

using AspNetCoreJsModules;

JsModuleContext jsModuleContext = HttpContext.GetJsModuleContext();
jsModuleContext.AddModuleImport("my-module", "path-to-my-module.js");
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.1.1 453 4/4/2022
0.1.0 406 3/26/2022