@@ -34,6 +34,8 @@ import {
3434 assetUrlRE ,
3535 checkPublicFile ,
3636 getAssetFilename ,
37+ getPublicAssetFilename ,
38+ publicAssetUrlRE ,
3739 urlToBuiltUrl
3840} from './asset'
3941import { isCSSRequest } from './css'
@@ -613,13 +615,16 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
613615 for ( const [ id , html ] of processedHtml ) {
614616 const relativeUrlPath = path . posix . relative ( config . root , id )
615617 const assetsBase = getBaseInHTML ( relativeUrlPath , config )
616- const toOutputAssetFilePath = ( filename : string ) => {
618+ const toOutputFilePath = (
619+ filename : string ,
620+ type : 'asset' | 'public'
621+ ) => {
617622 if ( isExternalUrl ( filename ) ) {
618623 return filename
619624 } else {
620625 return toOutputFilePathInHtml (
621626 filename ,
622- 'asset' ,
627+ type ,
623628 relativeUrlPath ,
624629 'html' ,
625630 config ,
@@ -628,6 +633,12 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
628633 }
629634 }
630635
636+ const toOutputAssetFilePath = ( filename : string ) =>
637+ toOutputFilePath ( filename , 'asset' )
638+
639+ const toOutputPublicAssetFilePath = ( filename : string ) =>
640+ toOutputFilePath ( filename , 'public' )
641+
631642 const isAsync = isAsyncScriptMap . get ( config ) ! . get ( id ) !
632643
633644 let result = html
@@ -716,6 +727,14 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
716727 )
717728 } )
718729
730+ result = result . replace ( publicAssetUrlRE , ( _ , fileHash ) => {
731+ return normalizePath (
732+ toOutputPublicAssetFilePath (
733+ getPublicAssetFilename ( fileHash , config ) !
734+ )
735+ )
736+ } )
737+
719738 if ( chunk && canInlineEntry ) {
720739 // all imports from entry have been inlined to html, prevent rollup from outputting it
721740 delete bundle [ chunk . fileName ]
0 commit comments