File tree Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -18,10 +18,10 @@ import {
18
18
getHash ,
19
19
isDataUrl ,
20
20
isExternalUrl ,
21
- isUrl ,
22
21
normalizePath ,
23
22
processSrcSet ,
24
23
removeLeadingSlash ,
24
+ urlCanParse ,
25
25
} from '../utils'
26
26
import type { ResolvedConfig } from '../config'
27
27
import { toOutputFilePathInHtml } from '../build'
@@ -823,7 +823,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
823
823
getPublicAssetFilename ( fileHash , config ) ! ,
824
824
)
825
825
826
- return isUrl ( publicAssetPath )
826
+ return urlCanParse ( publicAssetPath )
827
827
? publicAssetPath
828
828
: normalizePath ( publicAssetPath )
829
829
} )
Original file line number Diff line number Diff line change @@ -191,14 +191,17 @@ function testCaseInsensitiveFS() {
191
191
return fs . existsSync ( CLIENT_ENTRY . replace ( 'client.mjs' , 'cLiEnT.mjs' ) )
192
192
}
193
193
194
- export function isUrl ( path : string ) : boolean {
195
- try {
196
- new URL ( path )
197
- return true
198
- } catch {
199
- return false
200
- }
201
- }
194
+ export const urlCanParse =
195
+ URL . canParse ??
196
+ // URL.canParse is supported from Node.js 18.17.0+, 20.0.0+
197
+ ( ( path : string , base ?: string | undefined ) : boolean => {
198
+ try {
199
+ new URL ( path , base )
200
+ return true
201
+ } catch {
202
+ return false
203
+ }
204
+ } )
202
205
203
206
export const isCaseInsensitiveFS = testCaseInsensitiveFS ( )
204
207
You can’t perform that action at this time.
0 commit comments