Skip to content

Commit 490d3b0

Browse files
committed
SourceMap support
fixes webpack-contrib#30 fixes webpack/webpack#214
1 parent 4bd4f38 commit 490d3b0

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

addStyles.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ function listToStyles(list) {
8585
var id = item[0];
8686
var css = item[1];
8787
var media = item[2];
88-
// var sourceMap = item[3];
89-
var part = {css: css, media: media/*, sourceMap: sourceMap*/};
88+
var sourceMap = item[3];
89+
var part = {css: css, media: media, sourceMap: sourceMap};
9090
if(!newStyles[id])
9191
styles.push(newStyles[id] = {id: id, parts: [part]});
9292
else
@@ -123,7 +123,7 @@ function addStyle(obj, options) {
123123

124124
return function updateStyle(newObj) {
125125
if(newObj) {
126-
if(newObj.css === obj.css && newObj.media === obj.media /*&& newObj.sourceMap === obj.sourceMap*/)
126+
if(newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap)
127127
return;
128128
update(obj = newObj);
129129
} else {
@@ -166,13 +166,14 @@ function applyToSingletonTag(styleElement, index, remove, obj) {
166166
function applyToTag(styleElement, obj) {
167167
var css = obj.css;
168168
var media = obj.media;
169-
// var sourceMap = obj.sourceMap;
170-
// No browser support
171-
// if(sourceMap && typeof btoa === "function") {
172-
// try {
173-
// css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(JSON.stringify(sourceMap)) + " */";
174-
// } catch(e) {}
175-
// }
169+
var sourceMap = obj.sourceMap;
170+
171+
if(sourceMap && typeof btoa === "function") {
172+
try {
173+
css += "\n/*# sourceMappingURL=data:application/json;base64," + btoa(JSON.stringify(sourceMap)) + " */";
174+
css = "@import url(\"data:stylesheet/css;base64," + btoa(css) + "\")";
175+
} catch(e) {}
176+
}
176177

177178
if(media) {
178179
styleElement.setAttribute("media", media)

0 commit comments

Comments
 (0)