Este es un módulo independiente para agregar Vue CLI y soporte de CLI cuásar al núcleo ASPNET.
Vea los ejemplos aquí: https://github.com/eeparker/aspnetcore-vueclimiddleware/tree/master/samples
Primero, asegúrese de cambiar Vue CLI o Quasar CLI a los archivos de distribución de salida a wwwroot directamente (no DIST).
La razón para
Starting development server, el NPM-script que ejecuta el punto de control: aunque el servidor de Dev puede decirnos la URL en la que está escuchando, no lo hace hasta que haya terminado de compilar, e incluso entonces solo si no hubo advertencias de compiladores. Entonces, en lugar de esperar eso, considere listo tan pronto como comience a escuchar las solicitudes. Vea los códigos
Cuando se usa el MapToVueCliProxy o UseVueCli puede personalizar el comportamiento en función de su corredor o compilador de script NPM.
| Parámetro | Tipo | Descripción | Por defecto |
|---|---|---|---|
npmScript | cadena | El nombre del script en su archivo paquete.json que inicia el Vue-CLI, Quasar CLI u otro servidor web. | |
spaOptions | Spaoptions | Establezca la carpeta de la aplicación para que se proxen. | |
port | intencionalmente | Especifique el número de puerto del servidor VUE CLI. Esto también es utilizado por la opción Force-Kill para descubrir procesos utilizando el puerto. | 8080 |
https | bool | Establecer proxy para usar https | FALSO |
runner | enum { Npm, Yarn } | Especifique que el corredor, NPM y el hilo son opciones válidas. El soporte del hilo es experimental. | Npm |
regex | cadena | Texto importante para buscar en el registro NPM que indica que el servidor web se está ejecutando. Esto debe establecerse para Vue-Cli, Quasar y Quasar V2. (por ejemplo, running at , READY , APP Url ) | running at |
forceKill | bool | Intente matar el proceso de NPM al detener la depuración. | FALSO |
wsl | bool | Establecer en True si está utilizando WSL en Windows. Para otros sistemas operativos se ignorará. Esto cambia el nombre del proceso ejecutado a wsl en lugar de cmd . | FALSO |
Consulte migrar ASP.NET 2.2 a 3.0 Enrutamiento de punto final
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
} ) ;
}
} También es posible que deba agregar las siguientes tareas a su archivo csproj. Esto es similar a lo que se encuentran en las plantillas ASPNETSPA predeterminadas.
< 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 >
Debido a la discusión aquí, se decidió no incluirse en el paquete propiedad de Microsoft.