File tree 2 files changed +19
-24
lines changed
2 files changed +19
-24
lines changed Original file line number Diff line number Diff line change @@ -213,39 +213,27 @@ module.exports = function loader(content, map) {
213
213
placholderRegExps . urlItemG ,
214
214
( item ) => {
215
215
const match = placholderRegExps . urlItem . exec ( item ) ;
216
- let idx = Number ( match [ 1 ] ) ;
216
+ const idx = Number ( match [ 1 ] ) ;
217
217
218
218
if ( ! urlItems [ idx ] ) {
219
219
return item ;
220
220
}
221
221
222
222
const urlItem = urlItems [ idx ] ;
223
223
const { url } = urlItem ;
224
-
225
- idx = url . indexOf ( '?#' ) ;
226
-
227
- if ( idx < 0 ) {
228
- idx = url . indexOf ( '#' ) ;
229
- }
230
-
231
- let urlRequest ;
232
-
233
- if ( idx > 0 ) {
234
- // idx === 0 is catched by isUrlRequest
235
- // in cases like url('webfont.eot?#iefix')
236
- urlRequest = url . substr ( 0 , idx ) ;
237
- return `" + escape(require(${ stringifyRequest (
238
- this ,
239
- urlRequest
240
- ) } ) + "${ url . substr ( idx ) } ") + "`;
241
- }
242
-
243
- urlRequest = url ;
224
+ // Remove `#hash` and `?#hash` from `require`
225
+ const [ normalizedUrl , singleQuery , hashValue ] = url . split ( / ( \? ) ? # / ) ;
226
+ const hash =
227
+ singleQuery || hashValue
228
+ ? `"${ singleQuery ? '?' : '' } ${
229
+ hashValue ? `#${ hashValue } ` : ''
230
+ } "`
231
+ : '' ;
244
232
245
233
return `" + escape(require(${ stringifyRequest (
246
234
this ,
247
- urlRequest
248
- ) } )) + "`;
235
+ normalizedUrl
236
+ ) } )${ hash ? ` + ${ hash } ` : '' } ) + "`;
249
237
}
250
238
) ;
251
239
}
Original file line number Diff line number Diff line change @@ -82,13 +82,20 @@ function mapUrls(parsed, map) {
82
82
} ) ;
83
83
}
84
84
85
+ function uniq ( array ) {
86
+ return array . reduce (
87
+ ( acc , d ) => ( acc . indexOf ( d ) === - 1 ? [ ...acc , d ] : acc ) ,
88
+ [ ]
89
+ ) ;
90
+ }
91
+
85
92
module . exports = postcss . plugin (
86
93
pluginName ,
87
94
( options ) =>
88
95
function process ( css ) {
89
96
const urlItems = [ ] ;
90
97
const traversed = walkDeclsWithUrl ( css , ( value ) => isUrlRequest ( value ) ) ;
91
- const paths = flatten ( traversed . map ( ( item ) => item . values ) ) ;
98
+ const paths = uniq ( flatten ( traversed . map ( ( item ) => item . values ) ) ) ;
92
99
93
100
if ( paths . length === 0 ) {
94
101
return ;
You can’t perform that action at this time.
0 commit comments