css-loader 0.22.0 → 0.25.0
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 +28 -1
- package/lib/getLocalIdent.js +1 -1
- package/lib/loader.js +21 -18
- package/lib/localsLoader.js +1 -1
- package/lib/processCss.js +111 -56
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ Using 'Root-relative' urls is not recommended. You should only use it for legacy
|
|
|
62
62
|
|
|
63
63
|
### Local scope
|
|
64
64
|
|
|
65
|
-
By default CSS exports all class names into a global selector scope.
|
|
65
|
+
By default CSS exports all class names into a global selector scope. Styles can be locally scoped to avoid globally scoping styles.
|
|
66
66
|
|
|
67
67
|
The syntax `:local(.className)` can be used to declare `className` in the local scope. The local identifiers are exported by the module.
|
|
68
68
|
|
|
@@ -227,6 +227,33 @@ 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
|
+
|
|
236
|
+
### Camel case
|
|
237
|
+
|
|
238
|
+
By default, the exported JSON keys mirror the class names. If you want to camelize class names (useful in Javascript), pass the query parameter `camelCase` to the loader.
|
|
239
|
+
|
|
240
|
+
Example:
|
|
241
|
+
|
|
242
|
+
`css-loader?camelCase`
|
|
243
|
+
|
|
244
|
+
Usage:
|
|
245
|
+
```css
|
|
246
|
+
/* file.css */
|
|
247
|
+
|
|
248
|
+
.class-name { /* ... */ }
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
```js
|
|
252
|
+
// javascript
|
|
253
|
+
|
|
254
|
+
require('file.css').className
|
|
255
|
+
```
|
|
256
|
+
|
|
230
257
|
## License
|
|
231
258
|
|
|
232
259
|
MIT (http://www.opensource.org/licenses/mit-license.php)
|
package/lib/getLocalIdent.js
CHANGED
|
@@ -12,5 +12,5 @@ module.exports = function getLocalIdent(loaderContext, localIdentName, localName
|
|
|
12
12
|
options.content = options.hashPrefix + request + "+" + localName;
|
|
13
13
|
localIdentName = localIdentName.replace(/\[local\]/gi, localName);
|
|
14
14
|
var hash = loaderUtils.interpolateName(loaderContext, localIdentName, options);
|
|
15
|
-
return hash.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-").replace(/^([
|
|
15
|
+
return hash.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-").replace(/^((-?[0-9])|--)/, "_$1");
|
|
16
16
|
};
|
package/lib/loader.js
CHANGED
|
@@ -64,28 +64,31 @@ 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);
|
|
87
90
|
if (exportJs) {
|
|
88
|
-
exportJs = "exports.locals = " + exportJs;
|
|
91
|
+
exportJs = "exports.locals = " + exportJs + ";";
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
var moduleJs;
|
package/lib/localsLoader.js
CHANGED
package/lib/processCss.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
3
|
Author Tobias Koppers @sokra
|
|
4
4
|
*/
|
|
5
|
+
var formatCodeFrame = require("babel-code-frame");
|
|
5
6
|
var Tokenizer = require("css-selector-tokenizer");
|
|
6
7
|
var postcss = require("postcss");
|
|
7
8
|
var loaderUtils = require("loader-utils");
|
|
@@ -22,36 +23,41 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
|
|
|
22
23
|
var urlItems = [];
|
|
23
24
|
|
|
24
25
|
function replaceImportsInString(str) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
if(options.import) {
|
|
27
|
+
var tokens = str.split(/(\S+)/);
|
|
28
|
+
tokens = tokens.map(function (token) {
|
|
29
|
+
var importIndex = imports["$" + token];
|
|
30
|
+
if(typeof importIndex === "number") {
|
|
31
|
+
return "___CSS_LOADER_IMPORT___" + importIndex + "___";
|
|
32
|
+
}
|
|
33
|
+
return token;
|
|
34
|
+
});
|
|
35
|
+
return tokens.join("");
|
|
36
|
+
}
|
|
37
|
+
return str;
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
url
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
if(options.import) {
|
|
41
|
+
css.walkAtRules("import", function(rule) {
|
|
42
|
+
var values = Tokenizer.parseValues(rule.params);
|
|
43
|
+
var url = values.nodes[0].nodes[0];
|
|
44
|
+
if(url.type === "url") {
|
|
45
|
+
url = url.url;
|
|
46
|
+
} else if(url.type === "string") {
|
|
47
|
+
url = url.value;
|
|
48
|
+
} else throw rule.error("Unexpected format" + rule.params);
|
|
49
|
+
values.nodes[0].nodes.shift();
|
|
50
|
+
var mediaQuery = Tokenizer.stringifyValues(values);
|
|
51
|
+
if(loaderUtils.isUrlRequest(url, options.root) && options.mode === "global") {
|
|
52
|
+
url = loaderUtils.urlToRequest(url, options.root);
|
|
53
|
+
}
|
|
54
|
+
importItems.push({
|
|
55
|
+
url: url,
|
|
56
|
+
mediaQuery: mediaQuery
|
|
57
|
+
});
|
|
58
|
+
rule.remove();
|
|
52
59
|
});
|
|
53
|
-
|
|
54
|
-
});
|
|
60
|
+
}
|
|
55
61
|
|
|
56
62
|
css.walkRules(function(rule) {
|
|
57
63
|
if(rule.selector === ":export") {
|
|
@@ -77,31 +83,39 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
|
|
|
77
83
|
exports[exportName] = replaceImportsInString(exports[exportName]);
|
|
78
84
|
});
|
|
79
85
|
|
|
86
|
+
function processNode(item) {
|
|
87
|
+
switch (item.type) {
|
|
88
|
+
case "value":
|
|
89
|
+
item.nodes.forEach(processNode);
|
|
90
|
+
break;
|
|
91
|
+
case "nested-item":
|
|
92
|
+
item.nodes.forEach(processNode);
|
|
93
|
+
break;
|
|
94
|
+
case "item":
|
|
95
|
+
var importIndex = imports["$" + item.name];
|
|
96
|
+
if (typeof importIndex === "number") {
|
|
97
|
+
item.name = "___CSS_LOADER_IMPORT___" + importIndex + "___";
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case "url":
|
|
101
|
+
if (options.url && !/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
|
|
102
|
+
item.stringType = "";
|
|
103
|
+
delete item.innerSpacingBefore;
|
|
104
|
+
delete item.innerSpacingAfter;
|
|
105
|
+
var url = item.url;
|
|
106
|
+
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
|
|
107
|
+
urlItems.push({
|
|
108
|
+
url: url
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
80
115
|
css.walkDecls(function(decl) {
|
|
81
116
|
var values = Tokenizer.parseValues(decl.value);
|
|
82
117
|
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
|
-
});
|
|
118
|
+
value.nodes.forEach(processNode);
|
|
105
119
|
});
|
|
106
120
|
decl.value = Tokenizer.stringifyValues(values);
|
|
107
121
|
});
|
|
@@ -129,18 +143,22 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
129
143
|
|
|
130
144
|
var parserOptions = {
|
|
131
145
|
root: root,
|
|
132
|
-
mode: options.mode
|
|
146
|
+
mode: options.mode,
|
|
147
|
+
url: query.url !== false,
|
|
148
|
+
import: query.import !== false
|
|
133
149
|
};
|
|
134
150
|
|
|
135
151
|
var pipeline = postcss([
|
|
136
152
|
localByDefault({
|
|
137
153
|
mode: options.mode,
|
|
138
154
|
rewriteUrl: function(global, url) {
|
|
139
|
-
if(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
155
|
+
if(parserOptions.url){
|
|
156
|
+
if(!loaderUtils.isUrlRequest(url, root)) {
|
|
157
|
+
return url;
|
|
158
|
+
}
|
|
159
|
+
if(global) {
|
|
160
|
+
return loaderUtils.urlToRequest(url, root);
|
|
161
|
+
}
|
|
144
162
|
}
|
|
145
163
|
return url;
|
|
146
164
|
}
|
|
@@ -191,6 +209,43 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
191
209
|
urlItemRegExp: /___CSS_LOADER_URL___([0-9]+)___/
|
|
192
210
|
});
|
|
193
211
|
}).catch(function(err) {
|
|
194
|
-
|
|
212
|
+
if (err.name === 'CssSyntaxError') {
|
|
213
|
+
var wrappedError = new CSSLoaderError(
|
|
214
|
+
'Syntax Error',
|
|
215
|
+
err.reason,
|
|
216
|
+
err.line != null && err.column != null
|
|
217
|
+
? {line: err.line, column: err.column}
|
|
218
|
+
: null,
|
|
219
|
+
err.input.source
|
|
220
|
+
);
|
|
221
|
+
callback(wrappedError);
|
|
222
|
+
} else {
|
|
223
|
+
callback(err);
|
|
224
|
+
}
|
|
195
225
|
});
|
|
196
226
|
};
|
|
227
|
+
|
|
228
|
+
function formatMessage(message, loc, source) {
|
|
229
|
+
var formatted = message;
|
|
230
|
+
if (loc) {
|
|
231
|
+
formatted = formatted
|
|
232
|
+
+ ' (' + loc.line + ':' + loc.column + ')';
|
|
233
|
+
}
|
|
234
|
+
if (loc && source) {
|
|
235
|
+
formatted = formatted
|
|
236
|
+
+ '\n\n' + formatCodeFrame(source, loc.line, loc.column) + '\n';
|
|
237
|
+
}
|
|
238
|
+
return formatted;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function CSSLoaderError(name, message, loc, source, error) {
|
|
242
|
+
Error.call(this);
|
|
243
|
+
Error.captureStackTrace(this, CSSLoaderError);
|
|
244
|
+
this.name = name;
|
|
245
|
+
this.error = error;
|
|
246
|
+
this.message = formatMessage(message, loc, source);
|
|
247
|
+
this.hideStack = true;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
CSSLoaderError.prototype = Object.create(Error.prototype);
|
|
251
|
+
CSSLoaderError.prototype.constructor = CSSLoaderError;
|
package/package.json
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"author": "Tobias Koppers @sokra",
|
|
5
5
|
"description": "css loader module for webpack",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=0.12.0"
|
|
8
|
+
},
|
|
6
9
|
"dependencies": {
|
|
7
|
-
"
|
|
10
|
+
"babel-code-frame": "^6.11.0",
|
|
11
|
+
"css-selector-tokenizer": "^0.6.0",
|
|
8
12
|
"cssnano": ">=2.6.1 <4",
|
|
9
13
|
"loader-utils": "~0.2.2",
|
|
10
|
-
"object-assign": "^4.0.1",
|
|
11
14
|
"lodash.camelcase": "^3.0.1",
|
|
15
|
+
"object-assign": "^4.0.1",
|
|
12
16
|
"postcss": "^5.0.6",
|
|
13
|
-
"postcss-modules-extract-imports": "1.0.0
|
|
14
|
-
"postcss-modules-local-by-default": "^1.0.
|
|
15
|
-
"postcss-modules-scope": "1.0.0
|
|
17
|
+
"postcss-modules-extract-imports": "^1.0.0",
|
|
18
|
+
"postcss-modules-local-by-default": "^1.0.1",
|
|
19
|
+
"postcss-modules-scope": "^1.0.0",
|
|
16
20
|
"postcss-modules-values": "^1.1.0",
|
|
17
21
|
"source-list-map": "^0.1.4"
|
|
18
22
|
},
|