Este é um módulo independente para adicionar o suporte da CLI da VUE e do Quasar ao CORE ASPNET.
Veja os exemplos aqui: https://github.com/euparker/aspnetcore-vueclimiddleware/tree/master/samples
Primeiro, certifique -se de alternar a CLI ou a Quasar CLI para os arquivos de distribuição de saída para wwwroot diretamente (não dist).
O motivo para
Starting development server, o ponto de verificação de execução do NPM-Script: embora o servidor de dev possa eventualmente nos dizer o URL que está ouvindo, não o faz até terminar a compilação e, mesmo assim, apenas se não houvesse avisos do compilador. Então, em vez de esperar por isso, considere pronto assim que começar a ouvir solicitações. Veja os códigos
Ao usar o MapToVueCliProxy ou UseVueCli você pode personalizar o comportamento com base no seu Runner ou compilador de script npm.
| Parâmetro | Tipo | Descrição | Padrão |
|---|---|---|---|
npmScript | corda | O nome do script no seu arquivo package.json que inicia o vue-cli, a quase cli ou outro servidor da web. | |
spaOptions | Spaoptions | Defina a pasta do aplicativo a ser proxiada. | |
port | int | Especifique o número da porta do servidor VUE CLI. Isso também é usado pela opção Force-Mill para descobrir processos utilizando a porta. | 8080 |
https | bool | Defina proxy para usar https | falso |
runner | enum { Npm, Yarn } | Especifique o corredor, o npm e o fio são opções válidas. O suporte de fios é experimental. | Npm |
regex | corda | Texto importante para pesquisar no log NPM que indica que o servidor da Web está em execução. Isso deve ser definido para Vue-cli, Quasar e Quasar V2. (por exemplo, running at , READY , APP Url ) | running at |
forceKill | bool | Tente matar o processo da NPM ao interromper a depuração. | falso |
wsl | bool | Defina como true se você estiver usando o WSL no Windows. Para outros sistemas operacionais, ele será ignorado. Isso altera o nome do processo executado para wsl em vez de cmd . | falso |
Consulte Migrando asp.net 2.2 a 3.0 roteamento de terminal
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
} ) ;
}
} Você também pode precisar adicionar as seguintes tarefas ao seu arquivo csproj. Isso é semelhante ao encontrado nos modelos de ASPNetsPA padrão.
< 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 >
Devido à discussão aqui, foi decidido não ser incluído no pacote de propriedade da Microsoft.