8000 @import with .css files no longer precompiles. This gives us some extra · rusongyu/less.js@5d5024e · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d5024e

Browse files
author
cloudhead
committed
@import with .css files no longer precompiles. This gives us some extra
flexibility.
1 parent c60c2da commit 5d5024e

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

lib/less/tree/import.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,23 @@ if (typeof(require) !== 'undefined') { var tree = require('less/tree') }
1414
tree.Import = function Import(path, imports) {
1515
var that = this;
1616

17+
this._path = path;
18+
1719
// The '.less' extension is optional
1820
if (path instanceof tree.Quoted) {
1921
this.path = /\.(le?|c)ss$/.test(path.content) ? path.content : path.content + '.less';
2022
} else {
2123
this.path = path.value.content || path.value;
2224
}
2325

24-
imports.push(this.path, function (root) {
25-
that.root = root;
26-
});
26+
this.css = /css$/.test(this.path);
27+
28+
// Only pre-compile .less files
29+
if (! this.css) {
30+
imports.push(this.path, function (root) {
31+
that.root = root;
32+
});
33+
}
2734
};
2835

2936
//
@@ -36,16 +43,26 @@ tree.Import = function Import(path, imports) {
3643
// ruleset.
3744
//
3845
tree.Import.prototype = {
39-
toCSS: function () { return "" },
46+
toCSS: function () {
47+
if (this.css) {
48+
return "@import " + this._path.toCSS() + ';\n';
49+
} else {
50+
return "";
51+
}
52+
},
4053
eval: function () {
41-
for (var i = 0; i < this.root.rules.length; i++) {
42-
if (this.root.rules[i] instanceof tree.Import) {
43-
Array.prototype
44-
.splice
45-
.apply(this.root.rules,
46-
[i, 1].concat(this.root.rules[i].eval()));
54+
if (this.css) {
55+
return this;
56+
} else {
57+
for (var i = 0; i < this.root.rules.length; i++) {
58+
if (this.root.rules[i] instanceof tree.Import) {
59+
Array.prototype
60+
.splice
61+
.apply(this.root.rules,
62+
[i, 1].concat(this.root.rules[i].eval()));
63+
}
4764
}
65+
return this.root.rules;
4866
}
49-
return this.root.rules;
5067
}
5168
};

test/css/import.css

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#css {
2-
color: yellow;
3-
}
1+
@import "import-test-d.css";
42
#import {
53
color: red;
64
}

0 commit comments

Comments
 (0)
0