@@ -28,13 +28,15 @@ import {
28
28
ensureWatchedFile ,
29
29
fsPathFromId ,
30
30
injectQuery ,
31
+ isJSRequest ,
31
32
joinUrlSegments ,
32
33
normalizePath ,
33
34
processSrcSetSync ,
34
35
stripBase ,
35
36
unwrapId ,
36
37
wrapId ,
37
38
} from '../../utils'
39
+ import { isCSSRequest } from '../../plugins/css'
38
40
import { checkPublicFile } from '../../plugins/asset'
39
41
import { getCodeWithSourcemap , injectSourcesContent } from '../sourcemap'
40
42
@@ -82,6 +84,12 @@ function getHtmlFilename(url: string, server: ViteDevServer) {
82
84
}
83
85
}
84
86
87
+ function shouldPreTransform ( url : string , config : ResolvedConfig ) {
88
+ return (
89
+ ! checkPublicFile ( url , config ) && ( isJSRequest ( url ) || isCSSRequest ( url ) )
90
+ )
91
+ }
92
+
85
93
const processNodeUrl = (
86
94
attr : Token . Attribute ,
87
95
sourceCodeLocation : Token . Location ,
@@ -104,7 +112,7 @@ const processNodeUrl = (
104
112
// prefix with base (dev only, base is never relative)
105
113
const fullUrl = path . posix . join ( devBase , url )
106
114
overwriteAttrValue ( s , sourceCodeLocation , fullUrl )
107
- if ( server && ! checkPublicFile ( url , config ) ) {
115
+ if ( server && shouldPreTransform ( url , config ) ) {
108
116
preTransformRequest ( server , fullUrl , devBase )
109
117
}
110
118
} else if (
@@ -116,7 +124,7 @@ const processNodeUrl = (
116
124
// prefix with base (dev only, base is never relative)
117
125
const replacer = ( url : string ) => {
118
126
const fullUrl = path . posix . join ( devBase , url )
119
- if ( server && ! checkPublicFile ( url , config ) ) {
127
+ if ( server && shouldPreTransform ( url , config ) ) {
120
128
preTransformRequest ( server , fullUrl , devBase )
121
129
}
122
130
return fullUrl
0 commit comments