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拥有的软件包中。