Skip to content

Instantly share code, notes, and snippets.

@tgreensill
Created April 3, 2020 09:53
Show Gist options
  • Save tgreensill/3640d68efe301c65803e334033cadc94 to your computer and use it in GitHub Desktop.
Save tgreensill/3640d68efe301c65803e334033cadc94 to your computer and use it in GitHub Desktop.
AspNetCore Spa Service with Vue
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
// Wire up MVC and any other dependencies/services
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// In production, the files will be served from this directory.
services.AddSpaStaticFiles(options => options.RootPath = "wwwroot");
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Wire up middleware...
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
// No UseVueDevelopmentServer middleware so hack the react one for now...
spa.UseReactDevelopmentServer(npmScript: "serve");
}
});
}
}
module.exports = {
outputDir: './../wwwroot',
devServer: {
before() {
// Output the same message as the react dev server to get the
// Asp .Net Spa middleware working with vue.
console.info("Starting the development server...");
}
}
// Add any other configuration options...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment