AspNetWebpack 2.0.0
Renamed to AspNet.AssetManager in v3.0.0, which also supports Vite since v4.0.0. Install AspNet.AssetManager instead. The namespace changed to AspNet.AssetManager, AddAspNetWebpack() to AddAssetManager(), and bundle names now include the view folder (Views_Home_Index instead of Home_Index). v4.0.0 also renamed the Webpack configuration section to AssetManager. The release notes for v3.0.0 and v4.0.0 list every breaking change: https://github.com/Baune8D/AspNet.AssetManager/releases
dotnet add package AspNetWebpack --version 2.0.0
NuGet\Install-Package AspNetWebpack -Version 2.0.0
<PackageReference Include="AspNetWebpack" Version="2.0.0" />
<PackageVersion Include="AspNetWebpack" Version="2.0.0" />
<PackageReference Include="AspNetWebpack" />
paket add AspNetWebpack --version 2.0.0
#r "nuget: AspNetWebpack, 2.0.0"
#:package AspNetWebpack@2.0.0
#addin nuget:?package=AspNetWebpack&version=2.0.0
#tool nuget:?package=AspNetWebpack&version=2.0.0
AspNetWebpack
Asset utilities for AspNetWebpack
Initialize AssetService in Startup.cs:
public IConfiguration Configuration { get; }
public IWebHostEnvironment Env { get; }
public void ConfigureServices(IServiceCollection services)
{
...
services.AddAspNetWebpack(Configuration, Env);
}
Use extensions to get the bundle name:
var bundle = ViewData.GetBundleName() // Gets the bundle name from ViewData["Bundle"]
var bundle = Html.GetBundleName() // Gets the bundle name from the view context
Recommended use in eg. _Layout.cshtml:
var bundle = ViewData.GetBundleName() ?? Html.GetBundleName();
// Gets the bundle name from the view context but allows overriding it in ViewData["Bundle"]
Use AssetService to get assets:
@inject IAssetService AssetService
@await AssetService.AssetPath
// Generates: /Path/To/Assets
@await AssetService.GetBundlePathAsync("SomeBundle.js")
// Generates: /Path/To/Assets/SomeBundle.js?v=cache-buster
@await AssetService.GetScriptTagAsync("SomeBundle")
// Generates: <script src="/Path/To/Assets/SomeBundle.js?v=cache-buster"></script>
@await AssetService.GetLinkTagAsync("SomeBundle")
// Generates: <link href="/Path/To/Assets/SomeBundle.css?v=cache-buster" rel=\"stylesheet\" />
@await AssetService.GetStyleTagAsync("SomeBundle")
// Generates: <style>Inlined CSS</style
Overloads exists on GetBundlePathAsync in case no extension is applied to the bundle name.
Overloads exists on GetScriptTagAsync to change the load behaviour to eg. async and/or defer.
A fallback bundle can be set on: GetScriptTagAsync, GetLinkTagAsync, GetStyleTagAsync
@await AssetService.GetScriptTagAsync("SomeBundle", "FallbackBundle")
// Generates: <script src="/Path/To/Assets/SomeBundle.js?v=cache-buster"></script>
// Or if SomeBundle does not exist: <script src="/Path/To/Assets/FallbackBundle.js?v=cache-buster"></script>
Example _Layout.cshtml
@using AspNetWebpack
@inject IAssetService AssetService
@{
var bundle = ViewData.GetBundleName() ?? Html.GetBundleName();
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - AspNetWebpack</title>
@await RenderSectionAsync("Head", required: false)
@await AssetService.GetLinkTagAsync(bundle, "Layout");
@await RenderSectionAsync("Styles", required: false)
</head>
<body>
@RenderBody()
@await AssetService.GetScriptTagAsync(bundle, "Layout", ScriptLoad.Defer);
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- System.IO.Abstractions (>= 22.0.14)
-
net9.0
- System.IO.Abstractions (>= 22.0.14)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.