Inicie automaticamente um servidor de desenvolvimento de nós junto com um aplicativo ASP.NET Core.
O .NET SDK deve ser instalado.
O Node.js também precisa ser instalado para iniciar um servidor de desenvolvimento de nós.
Se você ainda não possui um, crie um novo aplicativo ASP.NET Core.
dotnet new web --output MyAspNetCoreAppAdicione o pacote BRUCE965.NODEDEVSERVER NUGET ao seu aplicativo ASP.NET Core.
dotnet add MyAspNetCoreApp package Bruce965.NodeDevServerSe você ainda não possui um, crie um novo aplicativo Node.js. Você pode usar o Vite ou qualquer outra estrutura à sua preferência.
npm create -y vite -- my-frontend --template vanillaConfigure o Node Development Server em seu arquivo program.cs .
WebApplicationBuilder builder = WebApplication . CreateBuilder ( args ) ;
// Configure the local Node development server.
builder . Services . AddNodeDevServer ( options =>
{
// You may need to tweak these options if you don't use Vite.
options . HostUri = "http://localhost:5173" ;
options . Path = "../my-frontend" ;
options . LaunchScript = "dev" ;
options . PackageManagers = [ "yarn" , "npm" ] ;
} ) ;
WebApplication app = builder . Build ( ) ;
// Some Node.js frameworks require this in order to support hot-reload.
app . UseWebSockets ( ) ;
app . UseRouting ( ) ;
app . UseEndpoints ( _ => { } ) ;
if ( app . Environment . IsDevelopment ( ) )
{
// In development, forward all requests to Node.js.
// The first request will automatically launch it.
app . UseNodeDevServer ( ) ;
}
else
{
// In production, use the pre-built files.
app . UseStaticFiles ( ) ;
}
app . Run ( ) ; Este projeto está licenciado sob a licença do MIT.
Alguns componentes podem estar disponíveis em outros lugares sob diferentes termos de licença, consulte os arquivos de origem individuais.