@@ -63,6 +63,11 @@ class SVGSpritePlugin {
6363 apply ( compiler ) {
6464 this . rules = getMatchedRule ( compiler ) ;
6565
66+ const path = this . rules . outputPath ? this . rules . outputPath : this . rules . publicPath ;
67+ this . filenamePrefix = path
68+ ? path . replace ( / ^ \/ / , '' )
69+ : '' ;
70+
6671 if ( compiler . hooks ) {
6772 compiler . hooks
6873 . thisCompilation
@@ -162,11 +167,8 @@ class SVGSpritePlugin {
162167 } )
163168 . then ( ( sprite ) => {
164169 const content = sprite . render ( ) ;
165- const filenamePrefix = this . rules . publicPath
166- ? this . rules . publicPath . replace ( / ^ \/ / , '' )
167- : '' ;
168170
169- compilation . assets [ `${ filenamePrefix } ${ filename } ` ] = {
171+ compilation . assets [ `${ this . filenamePrefix } ${ filename } ` ] = {
170172 source ( ) { return content ; } ,
171173 size ( ) { return content . length ; }
172174 } ;
@@ -209,11 +211,9 @@ class SVGSpritePlugin {
209211
210212 beforeHtmlGeneration ( compilation ) {
211213 const itemsBySprite = this . map . groupItemsBySpriteFilename ( ) ;
212- const filenamePrefix = this . rules . publicPath
213- ? this . rules . publicPath . replace ( / ^ \/ / , '' )
214- : '' ;
214+
215215 const sprites = Object . keys ( itemsBySprite ) . reduce ( ( acc , filename ) => {
216- acc [ filenamePrefix + filename ] = compilation . assets [ filenamePrefix + filename ] . source ( ) ;
216+ acc [ this . filenamePrefix + filename ] = compilation . assets [ this . filenamePrefix + filename ] . source ( ) ;
217217 return acc ;
218218 } , { } ) ;
219219
0 commit comments