@@ -14,22 +14,31 @@ function randomIdent() {
14
14
return "xxxHTMLLINKxxx" + Math . random ( ) + Math . random ( ) + "xxx" ;
15
15
} ;
16
16
17
+ function getLoaderConfig ( context ) {
18
+ var query = loaderUtils . parseQuery ( context . query ) ;
19
+ var configKey = query . config || 'htmlLoader' ;
20
+ var config = context . options && context . options . hasOwnProperty ( configKey ) ? context . options [ configKey ] : { } ;
21
+
22
+ delete query . config ;
23
+
24
+ return assign ( query , config ) ;
25
+ }
17
26
18
27
module . exports = function ( content ) {
19
28
this . cacheable && this . cacheable ( ) ;
20
- var query = loaderUtils . parseQuery ( this . query ) ;
29
+ var config = getLoaderConfig ( this ) ;
21
30
var attributes = [ "img:src" ] ;
22
- if ( query . attrs !== undefined ) {
23
- if ( typeof query . attrs === "string" )
24
- attributes = query . attrs . split ( " " ) ;
25
- else if ( Array . isArray ( query . attrs ) )
26
- attributes = query . attrs ;
27
- else if ( query . attrs === false )
31
+ if ( config . attrs !== undefined ) {
32
+ if ( typeof config . attrs === "string" )
33
+ attributes = config . attrs . split ( " " ) ;
34
+ else if ( Array . isArray ( config . attrs ) )
35
+ attributes = config . attrs ;
36
+ else if ( config . attrs === false )
28
37
attributes = [ ] ;
29
38
else
30
- throw new Error ( "Invalid value to query parameter attrs" ) ;
39
+ throw new Error ( "Invalid value to config parameter attrs" ) ;
31
40
}
32
- var root = query . root ;
41
+ var root = config . root ;
33
42
var links = attrParse ( content , function ( tag , attr ) {
34
43
return attributes . indexOf ( tag + ":" + attr ) >= 0 ;
35
44
} ) ;
@@ -57,8 +66,8 @@ module.exports = function(content) {
57
66
} ) ;
58
67
content . reverse ( ) ;
59
68
content = content . join ( "" ) ;
60
- if ( typeof query . minimize === "boolean" ? query . minimize : this . minimize ) {
61
- var minimizeOptions = assign ( { } , query ) ;
69
+ if ( typeof config . minimize === "boolean" ? config . minimize : this . minimize ) {
70
+ var minimizeOptions = assign ( { } , config ) ;
62
71
63
72
[
64
73
"removeComments" ,
@@ -82,7 +91,7 @@ module.exports = function(content) {
82
91
content = htmlMinifier . minify ( content , minimizeOptions ) ;
83
92
}
84
93
85
- if ( query . interpolate ) {
94
+ if ( config . interpolate ) {
86
95
content = compile ( '`' + content + '`' ) . code ;
87
96
} else {
88
97
content = JSON . stringify ( content ) ;
0 commit comments