WebpackTag 1.0.0

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

// Install WebpackTag as a Cake Tool
#tool nuget:?package=WebpackTag&version=1.0.0                

WebpackTag

NuGet version

WebpackTag is an ASP.NET Core Tag Helper for rendering links to CSS and JS files compiled via Webpack

Usage

Install the WebpackTag library using NuGet

Add the WebpackTag services to your Startup.cs:

using WebpackTag;
...
public void ConfigureServices(IServiceCollection services)
{
	services.AddWebpackTag();

Import the tag helpers in your Views/_ViewImports.cshtml file:

@addTagHelper *, WebpackTag

Then use the tag helpers in your view!

<webpack-styles />
<webpack-scripts />

These tag helpers will look for files called webpack-assets.json or asset-manifest.json in your wwwroot or SPA root directory, parse the contents, and render the correct <link> or <style> tags.

Note that when using assets-webpack-plugin, the entrypoints option should be enabled.

Multiple entry points

If your app has multiple entry points, you may specify the entry point name when using the tag

<webpack-styles entry="first" />

Configuration

Additional configuration can be performed when registering the services:

services.AddWebpackTag(options =>
{
	// ...
});

The following configuration options are available:

  • DevServerPort: Port the Webpack devserver is running on. If this is configured, the tag helpers will try hitting http://localhost:{port}/asset-manifest.json to load the manifest.
  • BaseUrl: Sets a string to prefix the generated URLs with. For example, this can be used to use a separate CDN domain in prod:
public class Startup
{
	private readonly IWebHostEnvironment _env;

	public Startup(IConfiguration configuration, IWebHostEnvironment env)
	{
		_env = env;
		Configuration = configuration;
	}

	public void ConfigureServices(IServiceCollection services)
	{
		services.AddWebpackTag(options =>
		{
			options.BaseUrl = _env.IsDevelopment() ? "/" : "https://cdn.example.com/";
		});
		// ...

Samples

This repository contains two samples:

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.0 is compatible.  netcoreapp3.1 was computed. 
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
1.0.0 11,245 11/16/2019