fix: do not publish manifest.json to static files folder.

This commit is contained in:
lchen committed 2026-10-21 14:57:52 +08:00
1 parent 5c81ed18b2
commit 27623a4e93
4 files changed
+16 -18

No files matched your search

+8 -13
View File
@@ -4,29 +4,24 @@ using System.Text.Json;
namespace WebApplication1;
#if DEBUG
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;
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);
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>
""";
#else
var manifestPath = Path.Combine(rootPath, "dist", ".vite", "manifest.json");
var manifestPath = Path.Combine(templateFolder, "manifest.json");
var manifestJson = await File.ReadAllTextAsync(manifestPath);
using var manifest = JsonDocument.Parse(manifestJson);