Skip to content

Commit e51dc40

Browse files
jonaskuskebluwy
andauthored
feat: read sec-fetch-dest header to detect JS in transform (#9981)
Co-authored-by: bluwy <[email protected]>
1 parent 7f9f8c6 commit e51dc40

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

packages/vite/src/node/server/middlewares/transform.ts

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export function transformMiddleware(
175175
}
176176

177177
if (
178+
req.headers['sec-fetch-dest'] === 'script' ||
178179
isJSRequest(url) ||
179180
isImportRequest(url) ||
180181
isCSSRequest(url) ||

packages/vite/src/node/utils.ts

+3
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ export const isDataUrl = (url: string): boolean => dataUrlRE.test(url)
271271
export const virtualModuleRE = /^virtual-module:.*/
272272
export const virtualModulePrefix = 'virtual-module:'
273273

274+
// NOTE: We should start relying on the "Sec-Fetch-Dest" header instead of this
275+
// hardcoded list. We can eventually remove this function when the minimum version
276+
// of browsers we support in dev all support this header.
274277
const knownJsSrcRE =
275278
/\.(?:[jt]sx?|m[jt]s|vue|marko|svelte|astro|imba|mdx)(?:$|\?)/
276279
export const isJSRequest = (url: string): boolean => {

0 commit comments

Comments
 (0)