Serve blazor.js in standalone site

This commit is contained in:
Steve Sanderson 2017-12-06 23:35:16 +00:00
parent a63b695db8
commit e2a7d4fa40
6 changed files with 40 additions and 5 deletions

View File

@ -6,5 +6,6 @@
</head>
<body>
<h1>Hello</h1>
<script src="/_framework/blazor.js"></script>
</body>
</html>
</html>

View File

@ -0,0 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
using System;
namespace Microsoft.Blazor.Browser
{
public class BlazorBrowserFileProvider : IFileProvider
{
private EmbeddedFileProvider _embeddedFiles = new EmbeddedFileProvider(
typeof(BlazorBrowserFileProvider).Assembly,
"blazor");
public IFileInfo GetFileInfo(string subpath)
=>_embeddedFiles.GetFileInfo(subpath.Replace('/', '$'));
public IDirectoryContents GetDirectoryContents(string subpath)
=> throw new NotImplementedException(); // Don't need to support this
public IChangeToken Watch(string filter)
=> throw new NotImplementedException(); // Don't need to support this
}
}

View File

@ -7,11 +7,15 @@
<DefaultItemExcludes>${DefaultItemExcludes};node_modules\**</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="2.0.0" />
</ItemGroup>
<Target Name="RunWebpack" BeforeTargets="PreBuildEvent">
<RemoveDir Directories="dist" />
<Exec Command="npm run build" WorkingDirectory="$(MSBuildThisFileDirectory)" />
<ItemGroup>
<EmbeddedResource Include="dist/blazor.js" LogicalName="blazor.js" />
<EmbeddedResource Include="dist/blazor.js" LogicalName="blazor.$blazor.js" />
</ItemGroup>
</Target>
</Project>

View File

@ -1,2 +1 @@
const abc: string = "Hello";
alert(abc);
console.log('Blazor is loading');

View File

@ -2,7 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Blazor.Browser;
using Microsoft.Blazor.Mono;
using Microsoft.Extensions.FileProviders;
using System.Collections.Generic;
using System.Net.Mime;
@ -15,7 +17,9 @@ namespace Microsoft.AspNetCore.Builder
applicationBuilder.UseStaticFiles(new StaticFileOptions
{
RequestPath = "/_framework",
FileProvider = new MonoStaticFileProvider(),
FileProvider = new CompositeFileProvider(
new MonoStaticFileProvider(),
new BlazorBrowserFileProvider()),
ContentTypeProvider = CreateContentTypeProvider(),
});
}

View File

@ -6,9 +6,11 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Composite" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.Blazor.Browser\Microsoft.Blazor.Browser.csproj" />
<ProjectReference Include="..\Microsoft.Blazor.Mono\Microsoft.Blazor.Mono.csproj" />
</ItemGroup>