Skip to content
This repository was archived by the owner on Feb 6, 2019. It is now read-only.

Commit 0698137

Browse files
committed
fix for empty css files
1 parent ccf989c commit 0698137

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

index.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,27 @@ module.exports = function(content) {
99
this.cacheable && this.cacheable();
1010
var result = [];
1111
var tree = csso.parse(content, "stylesheet");
12-
if(this && this.minimize) {
12+
if(tree && this && this.minimize) {
1313
tree = csso.compress(tree);
1414
tree = csso.cleanInfo(tree);
1515
}
1616

17-
var imports = extractImports(tree);
18-
annotateUrls(tree);
17+
if(tree) {
18+
var imports = extractImports(tree);
19+
annotateUrls(tree);
1920

20-
imports.forEach(function(imp) {
21-
if(imp.media.length > 0) {
22-
result.push(JSON.stringify("@media " + imp.media.join("") + "{"));
23-
}
24-
result.push("require(" + JSON.stringify("!" + __filename + "!" + urlToRequire(imp.url)) + ")");
25-
if(imp.media.length > 0) {
26-
result.push(JSON.stringify("}"));
27-
}
28-
});
21+
imports.forEach(function(imp) {
22+
if(imp.media.length > 0) {
23+
result.push(JSON.stringify("@media " + imp.media.join("") + "{"));
24+
}
25+
result.push("require(" + JSON.stringify("!" + __filename + "!" + urlToRequire(imp.url)) + ")");
26+
if(imp.media.length > 0) {
27+
result.push(JSON.stringify("}"));
28+
}
29+
});
30+
}
2931

30-
var css = JSON.stringify(csso.translate(tree));
32+
var css = JSON.stringify(tree ? csso.translate(tree) : "");
3133
var uriRegExp = /%CSSURL\[%(.*?)%\]CSSURL%/g;
3234
css = css.replace(uriRegExp, function(str) {
3335
var match = /^%CSSURL\[%(.*?)%\]CSSURL%$/.exec(str);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "css-loader",
3-
"version": "0.6.2",
3+
"version": "0.6.3",
44
"author": "Tobias Koppers @sokra",
55
"description": "css loader module for webpack",
66
"dependencies": {

test/urlTest.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ function testMinimize(name, input, result) {
3434
}
3535

3636
describe("url", function() {
37+
test("empty", "",
38+
["\"\""]);
39+
testMinimize("empty minimized", "",
40+
["\"\""]);
3741
test("simple", ".class { a: b c d; }",
3842
["\".class { a: b c d; }\""]);
3943
test("simple2", ".class { a: b c d; }\n.two {}",

0 commit comments

Comments
 (0)