@@ -2,7 +2,8 @@ var CleanCSS = require('./clean-css.js');
22var fs = require ( '@node/fs' ) ;
33var path = require ( '@node/path' ) ;
44
5- var cssInject = "(function(c){if (typeof document == 'undefined') return; var d=document,a='appendChild',i='styleSheet',s=d.createElement('style');s.type='text/css';d.getElementsByTagName('head')[0][a](s);s[i]?s[i].cssText=c:s[a](d.createTextNode(c));})" ;
5+ var cssInject = "(function(c){if (typeof document == 'undefined') return; var d=document,a='appendChild',i='styleSheet',s=d.createElement('style');s.type='text/css';d.getElementsByTagName('head')[0][a](s);s[a](d.createTextNode(c));})" ;
6+ var cssInjectSourceMaps = "(function(c){if (typeof document == 'undefined') return;var d=document,a='appendChild',s=d.createElement('link');s.rel='stylesheet';s.href='data:text/css;base64,' + btoa(unescape(encodeURIComponent(c)));d.getElementsByTagName('head')[0][a](s);})" ;
67
78function escape ( source ) {
89 return source
@@ -95,12 +96,15 @@ exports.bundle = function(loads, compileOpts, outputOpts) {
9596 fs . writeFileSync ( outFile , cssOutput ) ;
9697 }
9798 else {
98- // disabled pending https://bugs.chromium.org/p/chromium/issues/detail?id=649679&can=2&q=css%20source%20maps
99- //if (outputOpts.sourceMaps) {
100- // NB rebase source map paths to output path
101- // cssOutput += '\n/*# sourceMappingURL=data:application/json;base64,' + new Buffer(result.map.toString()).toString('base64') + '*/';
102- //}
103- return cssInject + '\n("' + escape ( cssOutput ) + '");' ;
99+ // this can be disabled pending https://bugs.chromium.org/p/chromium/issues/detail?id=649679&can=2&q=css%20source%20maps
100+ if ( outputOpts . sourceMaps && loader . inlineCssSourceMaps ) {
101+ var sourceMap = JSON . parse ( result . map . toString ( ) ) ;
102+ cssOutput += '\n/*# sourceMappingURL=data:application/json;base64,' + new Buffer ( JSON . stringify ( sourceMap ) ) . toString ( 'base64' ) + '*/' ;
103+ return cssInjectSourceMaps + '\n("' + escape ( cssOutput ) + '");' ;
104+ }
105+ else {
106+ return cssInject + '\n("' + escape ( cssOutput ) + '");' ;
107+ }
104108 }
105109 } ) ;
106110} ;
0 commit comments