fix: do not publish manifest.json to static files folder.
This commit is contained in:
1 parent
5c81ed18b2
commit
27623a4e93
4 files changed
+16
-18
No files matched your search
@@ -109,7 +109,7 @@ class PageExceptionFilterAttribute : ExceptionFilterAttribute
|
|||||||
var helper = context.HttpContext.RequestServices.GetRequiredService<ViteHelper>();
|
var helper = context.HttpContext.RequestServices.GetRequiredService<ViteHelper>();
|
||||||
var html = await helper.RenderAsync(
|
var html = await helper.RenderAsync(
|
||||||
context.HttpContext.Request.PathBase,
|
context.HttpContext.Request.PathBase,
|
||||||
"Templates/error.html",
|
"error.html",
|
||||||
"src/pages/error.ts",
|
"src/pages/error.ts",
|
||||||
new ApiErrorResult(errorCode, errorMessage),
|
new ApiErrorResult(errorCode, errorMessage),
|
||||||
new() { ["Title"] = "Error Page" });
|
new() { ["Title"] = "Error Page" });
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class DefaultController(ViteHelper vite) : SiteControllerBase(vite)
|
|||||||
|
|
||||||
var html = await viteHelper.RenderAsync(
|
var html = await viteHelper.RenderAsync(
|
||||||
Request.PathBase,
|
Request.PathBase,
|
||||||
"Templates/main.html",
|
"main.html",
|
||||||
"src/main.ts",
|
"src/main.ts",
|
||||||
new() { ["Title"] = "Home Page" });
|
new() { ["Title"] = "Home Page" });
|
||||||
|
|
||||||
|
|||||||
@@ -4,29 +4,24 @@ using System.Text.Json;
|
|||||||
|
|
||||||
namespace WebApplication1;
|
namespace WebApplication1;
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
public class ViteHelper(IOptions<JsonOptions> options)
|
public class ViteHelper(IOptions<JsonOptions> options)
|
||||||
{
|
{
|
||||||
#else
|
|
||||||
public class ViteHelper(IWebHostEnvironment env, IOptions<JsonOptions> options)
|
|
||||||
{
|
|
||||||
readonly string rootPath = env.WebRootPath ?? Path.Combine(AppContext.BaseDirectory, "wwwroot");
|
|
||||||
#endif
|
|
||||||
readonly JsonSerializerOptions jsonOptions = options.Value.JsonSerializerOptions;
|
readonly JsonSerializerOptions jsonOptions = options.Value.JsonSerializerOptions;
|
||||||
|
|
||||||
public Task<string> RenderAsync(string pathBase, string templatePath, string entryScript, Dictionary<string, string> stringTokens = null)
|
public Task<string> RenderAsync(string pathBase, string template, string entryScript, Dictionary<string, string> stringTokens = null)
|
||||||
{
|
{
|
||||||
return RenderInternalAsync(pathBase, templatePath, entryScript, null, stringTokens);
|
return RenderInternalAsync(pathBase, template, entryScript, null, stringTokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<string> RenderAsync<T>(string pathBase, string templatePath, string entryScript, T serverData = default, Dictionary<string, string> stringTokens = null)
|
public Task<string> RenderAsync<T>(string pathBase, string template, string entryScript, T serverData = default, Dictionary<string, string> stringTokens = null)
|
||||||
{
|
{
|
||||||
return RenderInternalAsync(pathBase, templatePath, entryScript, serverData, stringTokens);
|
return RenderInternalAsync(pathBase, template, entryScript, serverData, stringTokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task<string> RenderInternalAsync(string pathBase, string templatePath, string entryScript, object serverData = null, Dictionary<string, string> stringTokens = null)
|
async Task<string> RenderInternalAsync(string pathBase, string template, string entryScript, object serverData = null, Dictionary<string, string> stringTokens = null)
|
||||||
{
|
{
|
||||||
var path = Path.Combine(AppContext.BaseDirectory, templatePath);
|
var templateFolder = Path.Combine(AppContext.BaseDirectory, "Templates");
|
||||||
|
var path = Path.Combine(templateFolder, template);
|
||||||
var html = await File.ReadAllTextAsync(path);
|
var html = await File.ReadAllTextAsync(path);
|
||||||
|
|
||||||
if (stringTokens is not null)
|
if (stringTokens is not null)
|
||||||
@@ -47,7 +42,7 @@ public class ViteHelper(IWebHostEnvironment env, IOptions<JsonOptions> options)
|
|||||||
<script type="module" src="http://localhost:5173/{entryScript}"></script>
|
<script type="module" src="http://localhost:5173/{entryScript}"></script>
|
||||||
""";
|
""";
|
||||||
#else
|
#else
|
||||||
var manifestPath = Path.Combine(rootPath, "dist", ".vite", "manifest.json");
|
var manifestPath = Path.Combine(templateFolder, "manifest.json");
|
||||||
var manifestJson = await File.ReadAllTextAsync(manifestPath);
|
var manifestJson = await File.ReadAllTextAsync(manifestPath);
|
||||||
using var manifest = JsonDocument.Parse(manifestJson);
|
using var manifest = JsonDocument.Parse(manifestJson);
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,6 @@
|
|||||||
<None Update="Templates\**\*.html">
|
<None Update="Templates\**\*.html">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Include="wwwroot\dist\.vite\manifest.json">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -32,6 +29,12 @@
|
|||||||
<Message Importance="high" Text="Changes detected. Running npm run build..." />
|
<Message Importance="high" Text="Changes detected. Running npm run build..." />
|
||||||
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />
|
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />
|
||||||
<Touch Files="$(FrontendStampFile)" AlwaysCreate="true" />
|
<Touch Files="$(FrontendStampFile)" AlwaysCreate="true" />
|
||||||
|
<ItemGroup>
|
||||||
|
<ResolvedFileToPublish Include="$(MSBuildProjectDirectory)\wwwroot\dist\.vite\manifest.json">
|
||||||
|
<RelativePath>Templates\manifest.json</RelativePath>
|
||||||
|
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
|
||||||
|
</ResolvedFileToPublish>
|
||||||
|
</ItemGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Reference in new issue
Block a user