@@ -2,22 +2,22 @@ import path from 'path';
22import crypto from 'crypto' ;
33import Promise from 'bluebird' ;
44
5+ function ensureTrailingSlash ( string ) {
6+ if ( string . length && string . substr ( - 1 , 1 ) !== '/' ) {
7+ return `${ string } /` ;
8+ }
9+
10+ return string ;
11+ }
12+
513// Copied from html-webpack-plugin
6- function resolvePublicPath ( compilation , filename , publicPath ) {
7- let resolvedPublicPath ;
8- if ( typeof publicPath === 'undefined' ) {
9- /* istanbul ignore else */
10- resolvedPublicPath = typeof compilation . options . output . publicPath !== 'undefined'
14+ function resolvePublicPath ( compilation , filename ) {
15+ /* istanbul ignore else */
16+ const publicPath = typeof compilation . options . output . publicPath !== 'undefined'
1117 ? compilation . options . output . publicPath
1218 : path . relative ( path . dirname ( filename ) , '.' ) ; // TODO: How to test this? I haven't written this logic, unsure what it does
13- } else {
14- resolvedPublicPath = publicPath ;
15- }
1619
17- if ( resolvedPublicPath . length && resolvedPublicPath . substr ( - 1 , 1 ) !== '/' ) {
18- resolvedPublicPath = `${ resolvedPublicPath } /` ;
19- }
20- return resolvedPublicPath ;
20+ return ensureTrailingSlash ( publicPath ) ;
2121}
2222
2323function addFileToAssets ( compilation , htmlPluginData , { filepath, typeOfAsset = 'js' , includeSourcemap = true , hash = false , publicPath } ) {
@@ -36,8 +36,9 @@ function addFileToAssets(compilation, htmlPluginData, { filepath, typeOfAsset =
3636 suffix = `?${ md5 . digest ( 'hex' ) . substr ( 0 , 20 ) } ` ;
3737 }
3838
39- // TODO: No need to call this if `publicPath` is provided
40- const resolvedPublicPath = resolvePublicPath ( compilation , addedFilename , publicPath ) ;
39+ const resolvedPublicPath = typeof publicPath === 'undefined' ?
40+ resolvePublicPath ( compilation , addedFilename ) :
41+ ensureTrailingSlash ( publicPath ) ;
4142 const resolvedPath = `${ resolvedPublicPath } ${ addedFilename } ${ suffix } ` ;
4243
4344 htmlPluginData . assets [ typeOfAsset ] . unshift ( resolvedPath ) ;
0 commit comments