@@ -7,11 +7,11 @@ var parseSource = require("./parseSource");
7
7
var ReplaceMany = require ( "./ReplaceMany" ) ;
8
8
var loaderUtils = require ( "loader-utils" ) ;
9
9
var SourceListMap = require ( "source-list-map" ) . SourceListMap ;
10
- var fromStringWithSourceMap = require ( "source-list-map" ) . fromStringWithSourceMap ;
11
10
var CleanCSS = require ( "clean-css" ) ;
11
+ var getPlaceholderIdent = require ( "./getPlaceholderIdent" ) ;
12
12
13
13
module . exports = function ( content , map ) {
14
- this . cacheable && this . cacheable ( ) ;
14
+ if ( this . cacheable ) this . cacheable ( ) ;
15
15
var query = loaderUtils . parseQuery ( this . query ) ;
16
16
var root = query . root ;
17
17
var forceMinimize = query . minimize ;
@@ -49,16 +49,12 @@ module.exports = function(content, map) {
49
49
} ) ;
50
50
var placeholders = { } ;
51
51
stuff . placeholders . forEach ( function ( placeholder ) {
52
+ var ident ;
52
53
if ( ! placeholders [ placeholder . name ] ) {
53
- var hash = require ( "crypto" ) . createHash ( "md5" ) ;
54
- hash . update ( this . options && typeof this . options . context === "string" ?
55
- loaderUtils . stringifyRequest ( { context : this . options . context } , this . request ) :
56
- this . request ) ;
57
- hash . update ( placeholder . name ) ;
58
- var ident = "z" + hash . digest ( "hex" ) ;
54
+ ident = getPlaceholderIdent ( this , placeholder . name ) ;
59
55
placeholders [ placeholder . name ] = ident ;
60
56
} else {
61
- var ident = placeholders [ placeholder . name ] ;
57
+ ident = placeholders [ placeholder . name ] ;
62
58
}
63
59
replacer . replace ( placeholder . start , placeholder . length , placeholder . prefix + ident ) ;
64
60
} , this ) ;
@@ -77,6 +73,10 @@ module.exports = function(content, map) {
77
73
map = JSON . stringify ( map ) ;
78
74
}
79
75
76
+ function toEmbStr ( str ) {
77
+ return JSON . stringify ( str ) . replace ( / ^ " | " $ / g, "" ) ;
78
+ }
79
+
80
80
var css = JSON . stringify ( cssContent ) ;
81
81
82
82
var urlRegExp = / _ _ C S S L O A D E R U R L _ [ 0 - 9 ] + _ _ / g;
@@ -89,23 +89,19 @@ module.exports = function(content, map) {
89
89
var url = urlItem . url ;
90
90
if ( ! loaderUtils . isUrlRequest ( url , root ) )
91
91
return toEmbStr ( urlItem . raw ) ;
92
- var idx = url . indexOf ( "?#" ) ;
92
+ idx = url . indexOf ( "?#" ) ;
93
93
if ( idx < 0 ) idx = url . indexOf ( "#" ) ;
94
94
if ( idx > 0 ) {
95
95
// in cases like url('webfont.eot?#iefix')
96
- var request = url . substr ( 0 , idx ) ;
97
- return "\"+require(" + loaderUtils . stringifyRequest ( this , loaderUtils . urlToRequest ( request , root ) ) + ")+\"" + url . substr ( idx ) ;
96
+ var urlRequest = url . substr ( 0 , idx ) ;
97
+ return "\"+require(" + loaderUtils . stringifyRequest ( this , loaderUtils . urlToRequest ( urlRequest , root ) ) + ")+\"" + url . substr ( idx ) ;
98
98
} else if ( idx === 0 ) {
99
99
// only hash
100
100
return toEmbStr ( urlItem . raw ) ;
101
101
}
102
102
return "\"+require(" + loaderUtils . stringifyRequest ( this , loaderUtils . urlToRequest ( url , root ) ) + ")+\"" ;
103
103
} . bind ( this ) ) ;
104
104
105
- function toEmbStr ( str ) {
106
- return JSON . stringify ( str ) . replace ( / ^ " | " $ / g, "" ) ;
107
- }
108
-
109
105
if ( query . sourceMap && ! minimize ) {
110
106
var cssRequest = loaderUtils . getRemainingRequest ( this ) ;
111
107
var request = loaderUtils . getCurrentRequest ( this ) ;
@@ -137,4 +133,4 @@ module.exports = function(content, map) {
137
133
138
134
return "exports = module.exports = require(" + loaderUtils . stringifyRequest ( this , require . resolve ( "./css-base.js" ) ) + ")();\n" +
139
135
result . join ( "\n" ) ;
140
- }
136
+ } ;
0 commit comments