css-loader 0.23.0 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/lib/loader.js +20 -17
- package/lib/processCss.js +72 -55
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -227,6 +227,12 @@ You can also disable or enforce minification with the `minimize` query parameter
|
|
|
227
227
|
|
|
228
228
|
`require("css-loader?-minimize!./file.css")` (disabled)
|
|
229
229
|
|
|
230
|
+
### Disable behavior
|
|
231
|
+
|
|
232
|
+
`css-loader?-url` disables `url(...)` handling.
|
|
233
|
+
|
|
234
|
+
`css-loader?-import` disables `@import` handling.
|
|
235
|
+
|
|
230
236
|
## License
|
|
231
237
|
|
|
232
238
|
MIT (http://www.opensource.org/licenses/mit-license.php)
|
package/lib/loader.js
CHANGED
|
@@ -64,23 +64,26 @@ module.exports = function(content, map) {
|
|
|
64
64
|
"[" + JSON.stringify(importItem.export) + "] + \"";
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
cssAsString = cssAsString.replace(result.importItemRegExpG, importItemMatcher.bind(this))
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
url.substr(idx);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
67
|
+
cssAsString = cssAsString.replace(result.importItemRegExpG, importItemMatcher.bind(this));
|
|
68
|
+
if(query.url !== false) {
|
|
69
|
+
cssAsString = cssAsString.replace(result.urlItemRegExpG, function(item) {
|
|
70
|
+
var match = result.urlItemRegExp.exec(item);
|
|
71
|
+
var idx = +match[1];
|
|
72
|
+
var urlItem = result.urlItems[idx];
|
|
73
|
+
var url = urlItem.url;
|
|
74
|
+
idx = url.indexOf("?#");
|
|
75
|
+
if(idx < 0) idx = url.indexOf("#");
|
|
76
|
+
var urlRequest;
|
|
77
|
+
if(idx > 0) { // idx === 0 is catched by isUrlRequest
|
|
78
|
+
// in cases like url('webfont.eot?#iefix')
|
|
79
|
+
urlRequest = url.substr(0, idx);
|
|
80
|
+
return "\" + require(" + loaderUtils.stringifyRequest(this, urlRequest) + ") + \"" +
|
|
81
|
+
url.substr(idx);
|
|
82
|
+
}
|
|
83
|
+
urlRequest = url;
|
|
84
|
+
return "\" + require(" + loaderUtils.stringifyRequest(this, urlRequest) + ") + \"";
|
|
85
|
+
}.bind(this));
|
|
86
|
+
}
|
|
84
87
|
|
|
85
88
|
|
|
86
89
|
var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys);
|
package/lib/processCss.js
CHANGED
|
@@ -22,36 +22,41 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
|
|
|
22
22
|
var urlItems = [];
|
|
23
23
|
|
|
24
24
|
function replaceImportsInString(str) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
if(options.import) {
|
|
26
|
+
var tokens = str.split(/(\S+)/);
|
|
27
|
+
tokens = tokens.map(function (token) {
|
|
28
|
+
var importIndex = imports["$" + token];
|
|
29
|
+
if(typeof importIndex === "number") {
|
|
30
|
+
return "___CSS_LOADER_IMPORT___" + importIndex + "___";
|
|
31
|
+
}
|
|
32
|
+
return token;
|
|
33
|
+
});
|
|
34
|
+
return tokens.join("");
|
|
35
|
+
}
|
|
36
|
+
return str;
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
url
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
if(options.import) {
|
|
40
|
+
css.walkAtRules("import", function(rule) {
|
|
41
|
+
var values = Tokenizer.parseValues(rule.params);
|
|
42
|
+
var url = values.nodes[0].nodes[0];
|
|
43
|
+
if(url.type === "url") {
|
|
44
|
+
url = url.url;
|
|
45
|
+
} else if(url.type === "string") {
|
|
46
|
+
url = url.value;
|
|
47
|
+
} else throw rule.error("Unexpected format" + rule.params);
|
|
48
|
+
values.nodes[0].nodes.shift();
|
|
49
|
+
var mediaQuery = Tokenizer.stringifyValues(values);
|
|
50
|
+
if(loaderUtils.isUrlRequest(url, options.root) && options.mode === "global") {
|
|
51
|
+
url = loaderUtils.urlToRequest(url, options.root);
|
|
52
|
+
}
|
|
53
|
+
importItems.push({
|
|
54
|
+
url: url,
|
|
55
|
+
mediaQuery: mediaQuery
|
|
56
|
+
});
|
|
57
|
+
rule.remove();
|
|
52
58
|
});
|
|
53
|
-
|
|
54
|
-
});
|
|
59
|
+
}
|
|
55
60
|
|
|
56
61
|
css.walkRules(function(rule) {
|
|
57
62
|
if(rule.selector === ":export") {
|
|
@@ -77,31 +82,39 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
|
|
|
77
82
|
exports[exportName] = replaceImportsInString(exports[exportName]);
|
|
78
83
|
});
|
|
79
84
|
|
|
85
|
+
function processNode(item) {
|
|
86
|
+
switch (item.type) {
|
|
87
|
+
case "value":
|
|
88
|
+
item.nodes.forEach(processNode);
|
|
89
|
+
break;
|
|
90
|
+
case "nested-item":
|
|
91
|
+
item.nodes.forEach(processNode);
|
|
92
|
+
break;
|
|
93
|
+
case "item":
|
|
94
|
+
var importIndex = imports["$" + item.name];
|
|
95
|
+
if (typeof importIndex === "number") {
|
|
96
|
+
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
case "url":
|
|
100
|
+
if (options.url && !/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
|
|
101
|
+
item.stringType = "";
|
|
102
|
+
delete item.innerSpacingBefore;
|
|
103
|
+
delete item.innerSpacingAfter;
|
|
104
|
+
var url = item.url;
|
|
105
|
+
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
|
|
106
|
+
urlItems.push({
|
|
107
|
+
url: url
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
80
114
|
css.walkDecls(function(decl) {
|
|
81
115
|
var values = Tokenizer.parseValues(decl.value);
|
|
82
116
|
values.nodes.forEach(function(value) {
|
|
83
|
-
value.nodes.forEach(
|
|
84
|
-
switch(item.type) {
|
|
85
|
-
case "item":
|
|
86
|
-
var importIndex = imports["$" + item.name];
|
|
87
|
-
if(typeof importIndex === "number") {
|
|
88
|
-
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
|
|
89
|
-
}
|
|
90
|
-
break;
|
|
91
|
-
case "url":
|
|
92
|
-
if(!/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
|
|
93
|
-
item.stringType = "";
|
|
94
|
-
delete item.innerSpacingBefore;
|
|
95
|
-
delete item.innerSpacingAfter;
|
|
96
|
-
var url = item.url;
|
|
97
|
-
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
|
|
98
|
-
urlItems.push({
|
|
99
|
-
url: url
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
117
|
+
value.nodes.forEach(processNode);
|
|
105
118
|
});
|
|
106
119
|
decl.value = Tokenizer.stringifyValues(values);
|
|
107
120
|
});
|
|
@@ -129,18 +142,22 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
129
142
|
|
|
130
143
|
var parserOptions = {
|
|
131
144
|
root: root,
|
|
132
|
-
mode: options.mode
|
|
145
|
+
mode: options.mode,
|
|
146
|
+
url: query.url !== false,
|
|
147
|
+
import: query.import !== false
|
|
133
148
|
};
|
|
134
149
|
|
|
135
150
|
var pipeline = postcss([
|
|
136
151
|
localByDefault({
|
|
137
152
|
mode: options.mode,
|
|
138
153
|
rewriteUrl: function(global, url) {
|
|
139
|
-
if(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
154
|
+
if(parserOptions.url){
|
|
155
|
+
if(!loaderUtils.isUrlRequest(url, root)) {
|
|
156
|
+
return url;
|
|
157
|
+
}
|
|
158
|
+
if(global) {
|
|
159
|
+
return loaderUtils.urlToRequest(url, root);
|
|
160
|
+
}
|
|
144
161
|
}
|
|
145
162
|
return url;
|
|
146
163
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"author": "Tobias Koppers @sokra",
|
|
5
5
|
"description": "css loader module for webpack",
|
|
6
6
|
"dependencies": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"lodash.camelcase": "^3.0.1",
|
|
12
12
|
"postcss": "^5.0.6",
|
|
13
13
|
"postcss-modules-extract-imports": "^1.0.0",
|
|
14
|
-
"postcss-modules-local-by-default": "^1.0.
|
|
14
|
+
"postcss-modules-local-by-default": "^1.0.1",
|
|
15
15
|
"postcss-modules-scope": "^1.0.0",
|
|
16
16
|
"postcss-modules-values": "^1.1.0",
|
|
17
17
|
"source-list-map": "^0.1.4"
|