aspnetcore vueclimiddleware
5.0.0
これは、ASPNETコアにVue CLIとQuasar CLIのサポートを追加するスタンドアロンモジュールです。
https://github.com/eeparker/aspnetcore-vueclimiddleware/tree/master/samplesをご覧ください
まず、Vue CLIまたはQuasar CLIを切り替えて、配信ファイルをwwwrootに直接出力します(distではありません)。
Starting development server理由、NPM-Scriptの実行チェックポイント:DEVサーバーは最終的に聴いているURLを教えてくれるかもしれませんが、コンパイルが完了するまではそうしません。ですから、それを待つ代わりに、リクエストを聞き始めたらすぐに準備ができていると考えてください。
MapToVueCliProxyまたはUseVueCliを使用する場合、NPMスクリプトランナーまたはコンパイラに基づいて動作をカスタマイズできます。
| パラメーター | タイプ | 説明 | デフォルト |
|---|---|---|---|
npmScript | 弦 | Vue-Cli、Quasar CLI、またはその他のWebサーバーを起動するPackage.jsonファイルのスクリプトの名前。 | |
spaOptions | スパプション | プロキシになるアプリのフォルダーを設定します。 | |
port | int | Vue CLIサーバーポート番号を指定します。これは、ポートを利用するプロセスを発見するために、フォースキルオプションでも使用されます。 | 8080 |
https | ブール | HTTPSを使用するようにプロキシを設定します | 間違い |
runner | enum { Npm, Yarn } | ランナー、NPMとYARNを指定することは有効なオプションです。糸のサポートは実験的です。 | npm |
regex | 弦 | Webサーバーが実行されていることを示すNPMログで検索する重要なテキスト。これは、Vue-Cli、Quasar、およびQuasar V2に設定する必要があります。 (例えば、 running at 、 READY 、 APP Url ) | running at |
forceKill | ブール | デバッグを停止するときに、NPMプロセスを殺そうとします。 | 間違い |
wsl | ブール | WindowsでWSLを使用している場合はTRUEに設定します。他のオペレーティングシステムでは無視されます。これにより、実行されたプロセス名がcmdではなくwslに変更されます。 | 間違い |
ASP.NETの移行2.2から3.0エンドポイントルーティングを参照してください
public class Startup {
public Startup ( IConfiguration configuration )
{
Configuration = configuration ;
}
public IConfiguration Configuration { get ; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices ( IServiceCollection services )
{
// NOTE: PRODUCTION Ensure this is the same path that is specified in your webpack output
services . AddSpaStaticFiles ( opt => opt . RootPath = "ClientApp/dist" ) ;
services . AddControllers ( ) ;
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
{
// optional base path for IIS virtual app/directory
app . UsePathBase ( "/optionalpath" ) ;
// PRODUCTION uses webpack static files
app . UseSpaStaticFiles ( ) ;
// Routing
app . UseRouting ( ) ;
app . UserAuthorization ( ) ;
app . UseEndpoints ( endpoints =>
{
endpoints . MapControllers ( ) ;
endpoints . MapToVueCliProxy (
"{*path}" ,
new SpaOptions { SourcePath = "ClientApp" } ,
npmScript : ( System . Diagnostics . Debugger . IsAttached ) ? "serve" : null ,
regex : "Compiled successfully" ,
forceKill : true ,
wsl : false // Set to true if you are using WSL on windows. For other operating systems it will be ignored
) ;
} ) ;
}
} using VueCliMiddleware ;
public class Startup
{
public Startup ( IConfiguration configuration )
{
Configuration = configuration ;
}
public IConfiguration Configuration { get ; }
public virtual void ConfigureServices ( IServiceCollection services )
{
services . AddMvc ( ) ; // etc
// Need to register ISpaStaticFileProvider for UseSpaStaticFiles middleware to work
services . AddSpaStaticFiles ( configuration => { configuration . RootPath = "ClientApp/dist" ; } ) ;
}
public virtual void Configure ( IApplicationBuilder app , IHostingEnvironment env )
{
// your config opts...
// optional basepath
// app.UsePathBase("/myapp");
// add static files from SPA (/dist)
app . UseSpaStaticFiles ( ) ;
app . UseMvc ( routes => /* configure*/ ) ;
app . UseSpa ( spa =>
{
spa . Options . SourcePath = "ClientApp" ;
#if DEBUG
if ( env . IsDevelopment ( ) )
{
spa . UseVueCli ( npmScript : "serve" , port : 8080 ) ; // optional port
}
#endif
} ) ;
}
} また、次のタスクをCSPROJファイルに追加する必要があります。これは、デフォルトのASPNETSPAテンプレートにあるものに似ています。
< PropertyGroup >
<!-- Typescript/Javascript Client Configuration -->
< SpaRoot >ClientApp</ SpaRoot >
< DefaultItemExcludes >$(DefaultItemExcludes);$(SpaRoot)node_modules**</ DefaultItemExcludes >
</ PropertyGroup >
< Target Name = " DebugEnsureNodeEnv " BeforeTargets = " Build " >
<!-- Build Target: Ensure Node.js is installed -->
< Exec Command = " node --version " ContinueOnError = " true " >
< Output TaskParameter = " ExitCode " PropertyName = " ErrorCode " />
</ Exec >
< Error Condition = " '$(ErrorCode)' != '0' " Text = " Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE. " />
</ Target >
< Target Name = " DebugEnsureNpm " AfterTargets = " DebugEnsureNodeEnv " >
<!-- Build Target: Ensure Node.js is installed -->
< Exec Command = " npm --version " ContinueOnError = " true " >
< Output TaskParameter = " ExitCode " PropertyName = " ErrorCode " />
</ Exec >
</ Target >
< Target Name = " EnsureNodeModulesInstalled " BeforeTargets = " Build " Inputs = " package.json " Outputs = " packages-lock.json " >
<!-- Build Target: Restore NPM packages using npm -->
< Message Importance = " high " Text = " Restoring dependencies using 'npm'. This may take several minutes... " />
< Exec WorkingDirectory = " $(SpaRoot) " Command = " npm install " />
</ Target >
< Target Name = " PublishRunWebpack " AfterTargets = " ComputeFilesToPublish " >
<!-- Build Target: Run webpack dist build -->
< Message Importance = " high " Text = " Running npm build... " />
< Exec WorkingDirectory = " $(SpaRoot) " Command = " npm run build " />
<!-- Include the newly-built files in the publish output -->
< ItemGroup >
< DistFiles Include = " $(SpaRoot)dist** " />
< ResolvedFileToPublish Include = " @(DistFiles->'%(FullPath)') " Exclude = " @(ResolvedFileToPublish) " >
< RelativePath >%(DistFiles.Identity)</ RelativePath >
< CopyToPublishDirectory >PreserveNewest</ CopyToPublishDirectory >
</ ResolvedFileToPublish >
</ ItemGroup >
</ Target >
ここでの議論のために、Microsoft所有のパッケージに含まれないことが決定されました。