@@ -3,18 +3,24 @@ import crypto from 'crypto';
33import Promise from 'bluebird' ;
44
55// Copied from html-webpack-plugin
6- function resolvePublicPath ( compilation , filename ) {
7- let publicPath = typeof compilation . options . output . publicPath !== 'undefined'
8- ? compilation . options . output . publicPath
9- : path . relative ( path . dirname ( filename ) , '.' ) ;
6+ function resolvePublicPath ( compilation , filename , publicPath ) {
7+ let resolvedPublicPath ;
8+ if ( typeof publicPath === 'undefined' ) {
9+ resolvedPublicPath = typeof compilation . options . output . publicPath !== 'undefined'
10+ ? compilation . options . output . publicPath
11+ : path . relative ( path . dirname ( filename ) , '.' ) ;
12+ } else {
13+ resolvedPublicPath = publicPath ;
14+ }
1015
11- if ( publicPath . length && publicPath . substr ( - 1 , 1 ) !== '/' ) {
12- publicPath += '/' ;
16+ if ( resolvedPublicPath . length && resolvedPublicPath . substr ( - 1 , 1 ) !== '/' ) {
17+ resolvedPublicPath += '/' ;
1318 }
14- return publicPath ;
19+ return resolvedPublicPath ;
1520}
1621
17- function addFileToAssets ( htmlPluginData , compilation , { filename, typeOfAsset = 'js' , includeSourcemap = true , hash = false } = { } ) {
22+ function addFileToAssets ( htmlPluginData , compilation ,
23+ { filename, typeOfAsset = 'js' , includeSourcemap = true , hash = false , publicPath } = { } ) {
1824 if ( ! filename ) return compilation . errors . push ( new Error ( 'No filename defined' ) ) ;
1925
2026 return htmlPluginData . plugin . addFileToAssets ( filename , compilation )
@@ -25,7 +31,8 @@ function addFileToAssets(htmlPluginData, compilation, { filename, typeOfAsset =
2531 md5 . update ( compilation . assets [ addedFilename ] . source ( ) ) ;
2632 suffix = `?${ md5 . digest ( 'hex' ) . substr ( 0 , 20 ) } ` ;
2733 }
28- return htmlPluginData . assets [ typeOfAsset ] . unshift ( `${ resolvePublicPath ( compilation , addedFilename ) } ${ addedFilename } ${ suffix } ` ) ;
34+ return htmlPluginData . assets [ typeOfAsset ]
35+ . unshift ( `${ resolvePublicPath ( compilation , addedFilename , publicPath ) } ${ addedFilename } ${ suffix } ` ) ;
2936 } )
3037 . then ( ( ) => {
3138 if ( includeSourcemap ) {
0 commit comments