File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 1+ import path from 'path'
2+
3+ // Copied from html-webpack-plugin
4+ function resolvePublicPath ( compilation , filename ) {
5+ let publicPath = typeof compilation . options . output . publicPath !== 'undefined'
6+ ? compilation . options . output . publicPath
7+ : path . relative ( path . dirname ( filename ) , '.' )
8+
9+ if ( publicPath . length && publicPath . substr ( - 1 , 1 ) !== '/' ) {
10+ publicPath += '/'
11+ }
12+ return publicPath
13+ }
14+
115export default class AddAssetHtmlPlugin {
216 constructor ( {
317 filename,
@@ -13,9 +27,11 @@ export default class AddAssetHtmlPlugin {
1327 compiler . plugin ( 'compilation' , ( compilation ) => {
1428 if ( ! this . filename ) return compilation . errors . push ( new Error ( 'No filename defined' ) )
1529
30+ const publicPath = resolvePublicPath ( compilation , this . filename )
31+
1632 compilation . plugin ( 'html-webpack-plugin-before-html-processing' , ( htmlPluginData , callback ) => {
1733 htmlPluginData . plugin . addFileToAssets ( this . filename , compilation )
18- . then ( ( filename ) => htmlPluginData . assets [ this . typeOfAsset ] . unshift ( `/ ${ filename } ` ) )
34+ . then ( ( filename ) => htmlPluginData . assets [ this . typeOfAsset ] . unshift ( `${ publicPath } ${ filename } ` ) )
1935 . then ( ( ) => {
2036 if ( this . includeSourcemap ) {
2137 return htmlPluginData . plugin . addFileToAssets ( `${ this . filename } .map` , compilation )
You can’t perform that action at this time.
0 commit comments