NodeDevServer
v1.0.0
ASP.NETコアアプリケーションとともに、ノード開発サーバーを自動的に起動します。
.NET SDKをインストールする必要があります。
ノード開発サーバーを起動するには、node.jsもインストールする必要があります。
まだ持っていない場合は、新しいASP.NETコアアプリケーションを作成します。
dotnet new web --output MyAspNetCoreAppbruce965.nodedevserver nugetパッケージをASP.NETコアアプリケーションに追加します。
dotnet add MyAspNetCoreApp package Bruce965.NodeDevServerまだ持っていない場合は、新しいnode.jsアプリケーションを作成します。あなたは、あなたの好みでViteまたはその他のフレームワークを使用できます。
npm create -y vite -- my-frontend --template vanillaプログラムでノード開発サーバーを構成します。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ライセンスの下でライセンスされています。
一部のコンポーネントは、さまざまなライセンス条件で他の場所で利用できる場合があります。個々のソースファイルを参照してください。