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许可获得许可。
某些组件可以根据不同的许可条款在其他地方可用,请参阅各个源文件。