@@ -28,13 +28,15 @@ import {
2828 ensureWatchedFile ,
2929 fsPathFromId ,
3030 injectQuery ,
31+ isJSRequest ,
3132 joinUrlSegments ,
3233 normalizePath ,
3334 processSrcSetSync ,
3435 stripBase ,
3536 unwrapId ,
3637 wrapId ,
3738} from '../../utils'
39+ import { isCSSRequest } from '../../plugins/css'
3840import { checkPublicFile } from '../../plugins/asset'
3941import { getCodeWithSourcemap , injectSourcesContent } from '../sourcemap'
4042
@@ -82,6 +84,12 @@ function getHtmlFilename(url: string, server: ViteDevServer) {
8284 }
8385}
8486
87+ function shouldPreTransform ( url : string , config : ResolvedConfig ) {
88+ return (
89+ ! checkPublicFile ( url , config ) && ( isJSRequest ( url ) || isCSSRequest ( url ) )
90+ )
91+ }
92+
8593const processNodeUrl = (
8694 attr : Token . Attribute ,
8795 sourceCodeLocation : Token . Location ,
@@ -104,7 +112,7 @@ const processNodeUrl = (
104112 // prefix with base (dev only, base is never relative)
105113 const fullUrl = path . posix . join ( devBase , url )
106114 overwriteAttrValue ( s , sourceCodeLocation , fullUrl )
107- if ( server && ! checkPublicFile ( url , config ) ) {
115+ if ( server && shouldPreTransform ( url , config ) ) {
108116 preTransformRequest ( server , fullUrl , devBase )
109117 }
110118 } else if (
@@ -116,7 +124,7 @@ const processNodeUrl = (
116124 // prefix with base (dev only, base is never relative)
117125 const replacer = ( url : string ) => {
118126 const fullUrl = path . posix . join ( devBase , url )
119- if ( server && ! checkPublicFile ( url , config ) ) {
127+ if ( server && shouldPreTransform ( url , config ) ) {
120128 preTransformRequest ( server , fullUrl , devBase )
121129 }
122130 return fullUrl
0 commit comments