File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,30 @@ class HtmlWebpackInjectPreload implements WebpackPluginInstance {
82
82
compilation : Compilation ,
83
83
htmlPluginData : HtmlWebpackPluginData ,
84
84
) {
85
+ //Get public path
86
+ //html-webpack-plugin v5
87
+ let publicPath = htmlPluginData . publicPath ;
88
+
89
+ //html-webpack-plugin v4
90
+ if ( typeof publicPath === 'undefined' ) {
91
+ if (
92
+ htmlPluginData . plugin . options ?. publicPath &&
93
+ htmlPluginData . plugin . options ?. publicPath !== 'auto'
94
+ ) {
95
+ publicPath = htmlPluginData . plugin . options ?. publicPath ;
96
+ } else {
97
+ publicPath =
98
+ typeof compilation . options . output . publicPath === 'string'
99
+ ? compilation . options . output . publicPath
100
+ : '/' ;
101
+ }
102
+
103
+ //prevent wrong url
104
+ if ( publicPath [ publicPath . length - 1 ] !== '/' ) {
105
+ publicPath = publicPath + '/' ;
106
+ }
107
+ }
108
+
85
109
//Get assets name
86
110
const assets = new Set ( Object . keys ( compilation . assets ) ) ;
87
111
compilation . chunks . forEach ( chunk => {
@@ -105,7 +129,7 @@ class HtmlWebpackInjectPreload implements WebpackPluginInstance {
105
129
if ( href === false || typeof href === 'undefined' ) {
106
130
href = asset ;
107
131
}
108
- href = href [ 0 ] === '/' ? href : htmlPluginData . publicPath + href ;
132
+ href = href [ 0 ] === '/' ? href : publicPath + href ;
109
133
110
134
const preload : HtmlTagObject = {
111
135
tagName : 'link' ,
You can’t perform that action at this time.
0 commit comments