@@ -7,11 +7,11 @@ var parseSource = require("./parseSource");
77var ReplaceMany = require ( "./ReplaceMany" ) ;
88var loaderUtils = require ( "loader-utils" ) ;
99var SourceListMap = require ( "source-list-map" ) . SourceListMap ;
10- var fromStringWithSourceMap = require ( "source-list-map" ) . fromStringWithSourceMap ;
1110var CleanCSS = require ( "clean-css" ) ;
11+ var getPlaceholderIdent = require ( "./getPlaceholderIdent" ) ;
1212
1313module . exports = function ( content , map ) {
14- this . cacheable && this . cacheable ( ) ;
14+ if ( this . cacheable ) this . cacheable ( ) ;
1515 var query = loaderUtils . parseQuery ( this . query ) ;
1616 var root = query . root ;
1717 var forceMinimize = query . minimize ;
@@ -49,16 +49,12 @@ module.exports = function(content, map) {
4949 } ) ;
5050 var placeholders = { } ;
5151 stuff . placeholders . forEach ( function ( placeholder ) {
52+ var ident ;
5253 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 ) ;
5955 placeholders [ placeholder . name ] = ident ;
6056 } else {
61- var ident = placeholders [ placeholder . name ] ;
57+ ident = placeholders [ placeholder . name ] ;
6258 }
6359 replacer . replace ( placeholder . start , placeholder . length , placeholder . prefix + ident ) ;
6460 } , this ) ;
@@ -77,6 +73,10 @@ module.exports = function(content, map) {
7773 map = JSON . stringify ( map ) ;
7874 }
7975
76+ function toEmbStr ( str ) {
77+ return JSON . stringify ( str ) . replace ( / ^ " | " $ / g, "" ) ;
78+ }
79+
8080 var css = JSON . stringify ( cssContent ) ;
8181
8282 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) {
8989 var url = urlItem . url ;
9090 if ( ! loaderUtils . isUrlRequest ( url , root ) )
9191 return toEmbStr ( urlItem . raw ) ;
92- var idx = url . indexOf ( "?#" ) ;
92+ idx = url . indexOf ( "?#" ) ;
9393 if ( idx < 0 ) idx = url . indexOf ( "#" ) ;
9494 if ( idx > 0 ) {
9595 // 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 ) ;
9898 } else if ( idx === 0 ) {
9999 // only hash
100100 return toEmbStr ( urlItem . raw ) ;
101101 }
102102 return "\"+require(" + loaderUtils . stringifyRequest ( this , loaderUtils . urlToRequest ( url , root ) ) + ")+\"" ;
103103 } . bind ( this ) ) ;
104104
105- function toEmbStr ( str ) {
106- return JSON . stringify ( str ) . replace ( / ^ " | " $ / g, "" ) ;
107- }
108-
109105 if ( query . sourceMap && ! minimize ) {
110106 var cssRequest = loaderUtils . getRemainingRequest ( this ) ;
111107 var request = loaderUtils . getCurrentRequest ( this ) ;
@@ -137,4 +133,4 @@ module.exports = function(content, map) {
137133
138134 return "exports = module.exports = require(" + loaderUtils . stringifyRequest ( this , require . resolve ( "./css-base.js" ) ) + ")();\n" +
139135 result . join ( "\n" ) ;
140- }
136+ } ;
0 commit comments