File tree 3 files changed +27
-1
lines changed
packages/vite/src/node/server/middlewares
3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
16
16
isSameFileUri ,
17
17
normalizePath ,
18
18
removeLeadingSlash ,
19
+ urlRE ,
19
20
} from '../../utils'
20
21
import {
21
22
cleanUrl ,
@@ -86,7 +87,9 @@ export function servePublicMiddleware(
86
87
if (
87
88
( publicFiles && ! publicFiles . has ( toFilePath ( req . url ! ) ) ) ||
88
89
isImportRequest ( req . url ! ) ||
89
- isInternalRequest ( req . url ! )
90
+ isInternalRequest ( req . url ! ) ||
91
+ // for `/public-file.js?url` to be transformed
92
+ urlRE . test ( req . url ! )
90
93
) {
91
94
return next ( )
92
95
}
Original file line number Diff line number Diff line change @@ -143,6 +143,18 @@ describe('asset imports from js', () => {
143
143
"
144
144
` )
145
145
} )
146
+
147
+ test ( 'from /public (js)' , async ( ) => {
148
+ expect ( await page . textContent ( '.public-js-import' ) ) . toMatch (
149
+ '/foo/bar/raw.js' ,
150
+ )
151
+ expect ( await page . textContent ( '.public-js-import-content' ) )
152
+ . toMatchInlineSnapshot ( `
153
+ "document.querySelector('.raw-js').textContent =
154
+ '[success] Raw js from /public loaded'
155
+ "
156
+ ` )
157
+ } )
146
158
} )
147
159
148
160
describe ( 'css url() references' , ( ) => {
Original file line number Diff line number Diff line change @@ -31,6 +31,10 @@ <h2>Asset Imports from JS</h2>
31
31
From publicDir (json): < code class ="public-json-import "> </ code > Content:
32
32
< code class ="public-json-import-content "> </ code >
33
33
</ li >
34
+ < li >
35
+ From publicDir (js): < code class ="public-js-import "> </ code > Content:
36
+ < code class ="public-js-import-content "> </ code >
37
+ </ li >
34
38
</ ul >
35
39
36
40
< h2 > CSS url references</ h2 >
@@ -441,6 +445,13 @@ <h3>assets in noscript</h3>
441
445
text ( '.public-json-import-content' , await res . text ( ) )
442
446
} ) ( )
443
447
448
+ import publicJsUrl from '/raw.js?url'
449
+ text ( '.public-js-import' , publicJsUrl )
450
+ ; ( async ( ) => {
451
+ const res = await fetch ( publicJsUrl )
452
+ text ( '.public-js-import-content' , await res . text ( ) )
453
+ } ) ( )
454
+
444
455
import svgFrag from './nested/fragment.svg'
445
456
text ( '.svg-frag-import-path' , svgFrag )
446
457
document . querySelector ( '.svg-frag-import' ) . src = svgFrag + '#icon-heart-view'
You can’t perform that action at this time.
0 commit comments