GitXplorerGitXplorer
p

VueJsAspnetCoreTemplate

public
2 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
a2a1dc223bfa16fb11ebba5f5d62ee410e1bfa39

fix readme

committed 6 years ago
Unverified
5c0cfdd6a01d249808bdf1cb1941806d5a439dbf

update readme

committed 6 years ago
Unverified
326085899ef02eb436e817e900910184f0716076

add files

committed 6 years ago
Verified
60329f6d43e6401eb38e17b1b021d0b6705cd869

Initial commit

ppikax committed 6 years ago

README

The README file for this repository.

VueJsAspnetCore

Template to integrate VueJs on Visual Studio aspnetcore project.

Publish .csproj using vuejs as SPA

How to use

Requirements

Needs yarn, but you can adapt easily to use npm instead, just need to edit .csproj

Development

For development I recommend using yarn serve or npm run serve

Publish

dotnet publish or using Visual Studio

From the scratch

Create an empty aspnetcore project +2.0

Update .csproj

Add

  <!-- Build and copy files on publish -->
  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec Command="yarn" />

    <Exec Command="yarn build --mode production --dest dist --target app" />
    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="dist\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

if using npm

use

  <!-- Build and copy files on publish -->
  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec Command="npm install" />

    <Exec Command="npm run build --mode production --dest dist --target app" />
    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="dist\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

update Startup.cs

AddSpaStaticFiles

Add in ConfigureServices

services.AddSpaStaticFiles(x =>
{
    x.RootPath = "dist"; // set static files to dist
});

like this

public void ConfigureServices(IServiceCollection services)
{
    services.AddSpaStaticFiles(x =>
    {
        x.RootPath = "dist"; // set static files to dist
    });
}

Configure

Add in Configure

app.UseSpaStaticFiles(new StaticFileOptions()
{
#if !DEBUG
    OnPrepareResponse = ctx =>
    {
        // https://developers.google.com/web/fundamentals/performance/webpack/use-long-term-caching
        ctx.Context.Response.Headers[HeaderNames.CacheControl] = "max-age=" + 31536000;
    }  
#endif
});
app.UseSpa(x =>
{
    x.Options.DefaultPage = "/index.html";
});