@@ -2,7 +2,8 @@ var CleanCSS = require('./clean-css.js');
2
2
var fs = require ( '@node/fs' ) ;
3
3
var path = require ( '@node/path' ) ;
4
4
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);})" ;
6
7
7
8
function escape ( source ) {
8
9
return source
@@ -95,12 +96,15 @@ exports.bundle = function(loads, compileOpts, outputOpts) {
95
96
fs . writeFileSync ( outFile , cssOutput ) ;
96
97
}
97
98
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
+ }
104
108
}
105
109
} ) ;
106
110
} ;
0 commit comments