5
5
requestify ,
6
6
resolveRequests ,
7
7
isUrlRequestable ,
8
+ isDataUrl ,
8
9
WEBPACK_IGNORE_COMMENT_REGEXP ,
9
10
} from "../utils" ;
10
11
@@ -47,7 +48,7 @@ function getWebpackIgnoreCommentValue(index, nodes, inBetween) {
47
48
return matched && matched [ 2 ] === "true" ;
48
49
}
49
50
50
- function shouldHandleURL ( url , declaration , result ) {
51
+ function shouldHandleURL ( url , declaration , result , options ) {
51
52
if ( url . length === 0 ) {
52
53
result . warn ( `Unable to find uri in '${ declaration . toString ( ) } '` , {
53
54
node : declaration ,
@@ -56,14 +57,24 @@ function shouldHandleURL(url, declaration, result) {
56
57
return false ;
57
58
}
58
59
60
+ if ( isDataUrl ( url ) && options . isSupportDataURLInNewURL ) {
61
+ try {
62
+ decodeURIComponent ( url ) ;
63
+ } catch ( ignoreError ) {
64
+ return false ;
65
+ }
66
+
67
+ return true ;
68
+ }
69
+
59
70
if ( ! isUrlRequestable ( url ) ) {
60
71
return false ;
61
72
}
62
73
63
74
return true ;
64
75
}
65
76
66
- function parseDeclaration ( declaration , key , result ) {
77
+ function parseDeclaration ( declaration , key , result , options ) {
67
78
if ( ! needParseDeclaration . test ( declaration [ key ] ) ) {
68
79
return ;
69
80
}
@@ -130,7 +141,7 @@ function parseDeclaration(declaration, key, result) {
130
141
url = normalizeUrl ( url , isStringValue ) ;
131
142
132
143
// Do not traverse inside `url`
133
- if ( ! shouldHandleURL ( url , declaration , result ) ) {
144
+ if ( ! shouldHandleURL ( url , declaration , result , options ) ) {
134
145
// eslint-disable-next-line consistent-return
135
146
return false ;
136
147
}
@@ -186,7 +197,7 @@ function parseDeclaration(declaration, key, result) {
186
197
url = normalizeUrl ( url , isStringValue ) ;
187
198
188
199
// Do not traverse inside `url`
189
- if ( ! shouldHandleURL ( url , declaration , result ) ) {
200
+ if ( ! shouldHandleURL ( url , declaration , result , options ) ) {
190
201
// eslint-disable-next-line consistent-return
191
202
return false ;
192
203
}
@@ -229,7 +240,7 @@ function parseDeclaration(declaration, key, result) {
229
240
let url = normalizeUrl ( value , true ) ;
230
241
231
242
// Do not traverse inside `url`
232
- if ( ! shouldHandleURL ( url , declaration , result ) ) {
243
+ if ( ! shouldHandleURL ( url , declaration , result , options ) ) {
233
244
// eslint-disable-next-line consistent-return
234
245
return false ;
235
246
}
@@ -271,7 +282,12 @@ const plugin = (options = {}) => {
271
282
272
283
return {
273
284
Declaration ( declaration ) {
274
- const parsedURL = parseDeclaration ( declaration , "value" , result ) ;
285
+ const parsedURL = parseDeclaration (
286
+ declaration ,
287
+ "value" ,
288
+ result ,
289
+ options
290
+ ) ;
275
291
276
292
if ( ! parsedURL ) {
277
293
return ;
@@ -288,10 +304,15 @@ const plugin = (options = {}) => {
288
304
parsedDeclarations . map ( async ( parsedDeclaration ) => {
289
305
const { url } = parsedDeclaration ;
290
306
307
+ if ( isDataUrl ( url ) ) {
308
+ return parsedDeclaration ;
309
+ }
310
+
291
311
if ( options . filter ) {
292
312
const needKeep = await options . filter ( url ) ;
293
313
294
314
if ( ! needKeep ) {
315
+ // eslint-disable-next-line consistent-return
295
316
return ;
296
317
}
297
318
}
@@ -310,6 +331,7 @@ const plugin = (options = {}) => {
310
331
] ) ;
311
332
312
333
if ( ! resolvedUrl ) {
334
+ // eslint-disable-next-line consistent-return
313
335
return ;
314
336
}
315
337
0 commit comments