diff --git a/src/node/server/serverPluginVue.ts b/src/node/server/serverPluginVue.ts index e7ac4191ff9c24..8f11cde8314f76 100644 --- a/src/node/server/serverPluginVue.ts +++ b/src/node/server/serverPluginVue.ts @@ -319,7 +319,7 @@ async function resolveSrcImport( const importee = cleanUrl(resolveImport(root, importer, block.src!, resolver)) const filePath = resolver.requestToFile(importee) await cachedRead(ctx, filePath) - block.content = ctx.body + block.content = (ctx.body as Buffer).toString() // register HMR import relationship debugHmr(` ${importer} imports ${importee}`) diff --git a/src/node/utils/fsUtils.ts b/src/node/utils/fsUtils.ts index 7861a9e1dc90f7..6185ddcb27f400 100644 --- a/src/node/utils/fsUtils.ts +++ b/src/node/utils/fsUtils.ts @@ -12,7 +12,7 @@ const getETag = require('etag') interface CacheEntry { lastModified: number etag: string - content: string + content: Buffer } const fsReadCache = new LRUCache({ @@ -26,7 +26,7 @@ const fsReadCache = new LRUCache({ export async function cachedRead( ctx: Context | null, file: string -): Promise { +): Promise { const lastModified = fs.statSync(file).mtimeMs const cached = fsReadCache.get(file) if (ctx) { @@ -51,7 +51,8 @@ export async function cachedRead( } return cached.content } - const content = await fs.readFile(file, 'utf-8') + // #395 some file is an binary file, eg. font + const content = await fs.readFile(file) const etag = getETag(content) fsReadCache.set(file, { content,