Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dev): read file as buffer #398

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/node/server/serverPluginVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,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}`)
Expand Down
7 changes: 4 additions & 3 deletions src/node/utils/fsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getETag = require('etag')
interface CacheEntry {
lastModified: number
etag: string
content: string
content: Buffer
}

const fsReadCache = new LRUCache<string, CacheEntry>({
Expand All @@ -26,7 +26,7 @@ const fsReadCache = new LRUCache<string, CacheEntry>({
export async function cachedRead(
ctx: Context | null,
file: string
): Promise<string> {
): Promise<Buffer> {
const lastModified = fs.statSync(file).mtimeMs
const cached = fsReadCache.get(file)
if (ctx) {
Expand All @@ -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,
Expand Down