@@ -63,6 +63,11 @@ class SVGSpritePlugin {
63
63
apply ( compiler ) {
64
64
this . rules = getMatchedRule ( compiler ) ;
65
65
66
+ const path = this . rules . outputPath ? this . rules . outputPath : this . rules . publicPath ;
67
+ this . filenamePrefix = path
68
+ ? path . replace ( / ^ \/ / , '' )
69
+ : '' ;
70
+
66
71
if ( compiler . hooks ) {
67
72
compiler . hooks
68
73
. thisCompilation
@@ -162,11 +167,8 @@ class SVGSpritePlugin {
162
167
} )
163
168
. then ( ( sprite ) => {
164
169
const content = sprite . render ( ) ;
165
- const filenamePrefix = this . rules . publicPath
166
- ? this . rules . publicPath . replace ( / ^ \/ / , '' )
167
- : '' ;
168
170
169
- compilation . assets [ `${ filenamePrefix } ${ filename } ` ] = {
171
+ compilation . assets [ `${ this . filenamePrefix } ${ filename } ` ] = {
170
172
source ( ) { return content ; } ,
171
173
size ( ) { return content . length ; }
172
174
} ;
@@ -209,11 +211,9 @@ class SVGSpritePlugin {
209
211
210
212
beforeHtmlGeneration ( compilation ) {
211
213
const itemsBySprite = this . map . groupItemsBySpriteFilename ( ) ;
212
- const filenamePrefix = this . rules . publicPath
213
- ? this . rules . publicPath . replace ( / ^ \/ / , '' )
214
- : '' ;
214
+
215
215
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 ( ) ;
217
217
return acc ;
218
218
} , { } ) ;
219
219
0 commit comments