Skip to content

Commit

Permalink
fix: check type === 'js'
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Nov 24, 2023
1 parent 220a267 commit 6cfe433
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions packages/vite/src/node/server/middlewares/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,14 @@ export function transformMiddleware(
const type = isDirectCSSRequest(url) ? 'css' : 'js'
const isDep =
DEP_VERSION_RE.test(url) || depsOptimizer?.isOptimizedDepUrl(url)
const filepath =
result.map == null
? (await server.moduleGraph.getModuleByUrl(url, false))?.file
: undefined
const originalContent =
filepath != null ? await getOriginalContent(filepath) : undefined
let originalContent: string | undefined
if (type === 'js' && result.map == null) {
const filepath = (
await server.moduleGraph.getModuleByUrl(url, false)
)?.file
originalContent =
filepath != null ? await getOriginalContent(filepath) : undefined
}
return send(req, res, result.code, type, {
etag: result.etag,
// allow browser to cache npm deps!
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface SendOptions {
cacheControl?: string
headers?: OutgoingHttpHeaders
map?: SourceMap | { mappings: '' } | null
/** only used when map == null (when the fallback sourcemap is used) */
/** only used when type === 'js' && map == null (when the fallback sourcemap is used) */
originalContent?: string
}

Expand Down

0 comments on commit 6cfe433

Please sign in to comment.