NodeDevServer
v1.0.0
與ASP.NET Core應用程序一起自動啟動節點開發服務器。
必須安裝.NET SDK。
還需要安裝node.js才能啟動節點開發服務器。
如果您還沒有一個,請創建一個新的ASP.NET核心應用程序。
dotnet new web --output MyAspNetCoreApp將bruce965.nodedevserver nuget軟件包添加到ASP.NET Core應用程序中。
dotnet add MyAspNetCoreApp package Bruce965.NodeDevServer如果還沒有一個,請創建一個新的node.js應用程序。您可以優先使用Vite或任何其他框架。
npm create -y vite -- my-frontend --template vanilla在您的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 ( ) ; 該項目已根據MIT許可獲得許可。
某些組件可以根據不同的許可條款在其他地方可用,請參閱各個源文件。