Node.js hosting extensions
Este conteúdo não está disponível em sua língua ainda.
The Aspire Community Toolkit Node.js hosting extensions package provides extra functionality to the Aspire.Hosting.NodeJS hosting package.
This package provides the following features:
- Running Vite applications
- Running Node.js applications using Yarn and pnpm
- Ensuring that packages are installed before running the application (using the specified package manager)
Hosting integration
Section titled “Hosting integration”To get started with the Aspire Community Toolkit Node.js hosting extensions, install the CommunityToolkit.Aspire.Hosting.NodeJS.Extensions NuGet package in the app host project.
aspire add communitytoolkit-nodejs-extensionsA CLI Aspire é interativa; escolhe o resultado apropriado quando solicitado:
Select an integration to add:
> communitytoolkit-nodejs-extensions (CommunityToolkit.Aspire.Hosting.NodeJS.Extensions)> Other results listed as selectable options...#:package CommunityToolkit.Aspire.Hosting.NodeJS.Extensions@*<PackageReference Include="CommunityToolkit.Aspire.Hosting.NodeJS.Extensions" Version="*" />Run specific package managers
Section titled “Run specific package managers”This integration extension adds support for running Node.js applications using Yarn or pnpm as the package manager.
To add a Node.js application using Yarn, use the AddYarnApp extension method:
var builder = DistributedApplication.CreateBuilder(args);
var yarnApp = builder.AddYarnApp("yarn-demo") .WithExternalHttpEndpoints();
builder.AddProject<Projects.ExampleProject>() .WithReference(yarnApp);
// After adding all resources, run the app...To add a Node.js application using pnpm, use the AddPnpmApp extension method:
var builder = DistributedApplication.CreateBuilder(args);
var pnpmApp = builder.AddPnpmApp("pnpm-demo") .WithExternalHttpEndpoints();
builder.AddProject<Projects.ExampleProject>() .WithReference(pnpmApp);
// After adding all resources, run the app...Run Vite apps
Section titled “Run Vite apps”This integration extension adds support for running the development server for Vite applications. By default, it uses the npm package manager to launch, but this can be overridden with the packageManager argument.
Using npm (default)
Section titled “Using npm (default)”var builder = DistributedApplication.CreateBuilder(args);
var viteApp = builder.AddViteApp("vite-demo") .WithExternalHttpEndpoints();
// After adding all resources, run the app...Using Yarn
Section titled “Using Yarn”var builder = DistributedApplication.CreateBuilder(args);
var viteApp = builder.AddViteApp("yarn-demo", packageManager: "yarn") .WithExternalHttpEndpoints();
// After adding all resources, run the app...Using pnpm
Section titled “Using pnpm”var builder = DistributedApplication.CreateBuilder(args);
var viteApp = builder.AddViteApp("pnpm-demo", packageManager: "pnpm") .WithExternalHttpEndpoints();
// After adding all resources, run the app...Install packages
Section titled “Install packages”When using the WithNpmPackageInstallation, WithYarnPackageInstallation, or WithPnpmPackageInstallation methods, the package manager is used to install the packages before starting the application. These methods are useful to ensure that packages are installed before the application starts, similar to how a C# application would restore NuGet packages before running.
var builder = DistributedApplication.CreateBuilder(args);
var nodeApp = builder.AddNodeApp("node-demo", "server.js") .WithNpmPackageInstallation();
// After adding all resources, run the app...var builder = DistributedApplication.CreateBuilder(args);
var yarnApp = builder.AddYarnApp("yarn-demo") .WithYarnPackageInstallation();
// After adding all resources, run the app...var builder = DistributedApplication.CreateBuilder(args);
var pnpmApp = builder.AddPnpmApp("pnpm-demo") .WithPnpmPackageInstallation();
// After adding all resources, run the app...