aspnetcore vueclimiddleware
5.0.0
這是一個獨立的模塊,可將VUE CLI和類星體CLI支持添加到ASPNET Core。
請參閱此處的示例:https://github.com/eeparker/aspnetcore-vueclimiddleware/tree/master/samples
首先,請確保將VUE CLI或Quasar CLI切換為直接(不是DIST)的wwwroot輸出。
Starting development server的原因是NPM-Script運行檢查點:儘管開發服務器最終可能會告訴我們它正在偵聽的URL,但是直到完成編譯之前,它才能告訴我們,甚至只有沒有編譯器警告。因此,不要等待這一點,而是一旦開始收聽請求就可以準備就緒。請參閱代碼
使用MapToVueCliProxy或UseVueCli時,您可以根據NPM腳本跑步者或編譯器自定義行為。
| 範圍 | 類型 | 描述 | 預設 |
|---|---|---|---|
npmScript | 細繩 | package.json文件中的腳本名稱,該文件啟動了Vue-CLI,Quasar CLI或其他Web服務器。 | |
spaOptions | Spaoptions | 設置要代理應用程序的文件夾。 | |
port | int | 指定VUE CLI服務器端口號。強制殺手選項也使用了這一點,以發現利用端口的過程。 | 8080 |
https | 布爾 | 設置代理使用https | 錯誤的 |
runner | enum { Npm, Yarn } | 指定跑步者,NPM和紗線是有效的選項。紗線支撐是實驗性的。 | NPM |
regex | 細繩 | 在NPM日誌中搜索的重要文本,該日誌表明Web服務器正在運行。必須為Vue-CLI,Quasar和Quasar V2設置此設置。 (例如, running at , READY , APP Url跑步) | running at |
forceKill | 布爾 | 停止調試時嘗試殺死NPM過程。 | 錯誤的 |
wsl | 布爾 | 如果您在Windows上使用WSL,則設置為True。對於其他操作系統,它將被忽略。這將執行的過程名稱更改為wsl而不是cmd 。 | 錯誤的 |
請參閱遷移的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擁有的軟件包中。