css-loader 0.20.2 → 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/compile-exports.js +29 -0
- package/lib/getLocalIdent.js +6 -5
- package/lib/loader.js +24 -31
- package/lib/localsLoader.js +6 -8
- package/lib/processCss.js +76 -56
- package/package.json +4 -4
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)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var camelCase = require("lodash.camelcase");
|
|
2
|
+
|
|
3
|
+
function dashesCamelCase(str) {
|
|
4
|
+
return str.replace(/-(\w)/g, function(match, firstLetter) {
|
|
5
|
+
return firstLetter.toUpperCase();
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
module.exports = function compileExports(result, importItemMatcher, camelCaseKeys) {
|
|
10
|
+
if (!Object.keys(result.exports).length) {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var exportJs = Object.keys(result.exports).reduce(function(res, key) {
|
|
15
|
+
var valueAsString = JSON.stringify(result.exports[key]);
|
|
16
|
+
valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher);
|
|
17
|
+
res.push("\t" + JSON.stringify(key) + ": " + valueAsString);
|
|
18
|
+
|
|
19
|
+
if (camelCaseKeys === true) {
|
|
20
|
+
res.push("\t" + JSON.stringify(camelCase(key)) + ": " + valueAsString);
|
|
21
|
+
} else if (camelCaseKeys === 'dashes') {
|
|
22
|
+
res.push("\t" + JSON.stringify(dashesCamelCase(key)) + ": " + valueAsString);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return res;
|
|
26
|
+
}, []).join(",\n");
|
|
27
|
+
|
|
28
|
+
return "{\n" + exportJs + "\n}";
|
|
29
|
+
};
|
package/lib/getLocalIdent.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
Author Tobias Koppers @sokra
|
|
4
4
|
*/
|
|
5
5
|
var loaderUtils = require("loader-utils");
|
|
6
|
+
var path = require("path");
|
|
7
|
+
|
|
6
8
|
module.exports = function getLocalIdent(loaderContext, localIdentName, localName, options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
options.content =
|
|
11
|
-
options.context = loaderContext.options && typeof loaderContext.options.context === "string" ? loaderContext.options.context : loaderContext.context;
|
|
9
|
+
if(!options.context)
|
|
10
|
+
options.context = loaderContext.options && typeof loaderContext.options.context === "string" ? loaderContext.options.context : loaderContext.context;
|
|
11
|
+
var request = path.relative(options.context, loaderContext.resourcePath);
|
|
12
|
+
options.content = options.hashPrefix + request + "+" + localName;
|
|
12
13
|
localIdentName = localIdentName.replace(/\[local\]/gi, localName);
|
|
13
14
|
var hash = loaderUtils.interpolateName(loaderContext, localIdentName, options);
|
|
14
15
|
return hash.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-").replace(/^([^a-zA-Z_])/, "_$1");
|
package/lib/loader.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
var path = require("path");
|
|
6
6
|
var loaderUtils = require("loader-utils");
|
|
7
|
-
var camelCase = require("lodash.camelcase");
|
|
8
7
|
var processCss = require("./processCss");
|
|
9
8
|
var getImportPrefix = require("./getImportPrefix");
|
|
9
|
+
var compileExports = require("./compile-exports");
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
module.exports = function(content, map) {
|
|
@@ -64,40 +64,33 @@ 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
|
-
return "\" + require(" + loaderUtils.stringifyRequest(this, urlRequest) + ") + \"";
|
|
83
|
-
}.bind(this));
|
|
84
|
-
|
|
85
|
-
var exportJs = "";
|
|
86
|
-
if(Object.keys(result.exports).length > 0) {
|
|
87
|
-
var boundImportItemMatcher = importItemMatcher.bind(this);
|
|
88
|
-
exportJs = Object.keys(result.exports).reduce(function(res, key) {
|
|
89
|
-
var valueAsString = JSON.stringify(result.exports[key]);
|
|
90
|
-
valueAsString = valueAsString.replace(result.importItemRegExpG, boundImportItemMatcher);
|
|
91
|
-
res.push("\t" + JSON.stringify(key) + ": " + valueAsString);
|
|
92
|
-
if (camelCaseKeys) {
|
|
93
|
-
res.push("\t" + JSON.stringify(camelCase(key)) + ": " + valueAsString);
|
|
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);
|
|
94
82
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
urlRequest = url;
|
|
84
|
+
return "\" + require(" + loaderUtils.stringifyRequest(this, urlRequest) + ") + \"";
|
|
85
|
+
}.bind(this));
|
|
98
86
|
}
|
|
99
87
|
|
|
100
88
|
|
|
89
|
+
var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys);
|
|
90
|
+
if (exportJs) {
|
|
91
|
+
exportJs = "exports.locals = " + exportJs + ";";
|
|
92
|
+
}
|
|
93
|
+
|
|
101
94
|
var moduleJs;
|
|
102
95
|
if(query.sourceMap && result.map) {
|
|
103
96
|
// add a SourceMap
|
package/lib/localsLoader.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
var loaderUtils = require("loader-utils");
|
|
6
6
|
var processCss = require("./processCss");
|
|
7
7
|
var getImportPrefix = require("./getImportPrefix");
|
|
8
|
+
var compileExports = require("./compile-exports");
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
module.exports = function(content) {
|
|
@@ -12,6 +13,7 @@ module.exports = function(content) {
|
|
|
12
13
|
var callback = this.async();
|
|
13
14
|
var query = loaderUtils.parseQuery(this.query);
|
|
14
15
|
var moduleMode = query.modules || query.module;
|
|
16
|
+
var camelCaseKeys = query.camelCase || query.camelcase;
|
|
15
17
|
|
|
16
18
|
processCss(content, null, {
|
|
17
19
|
mode: moduleMode ? "local" : "global",
|
|
@@ -33,16 +35,12 @@ module.exports = function(content) {
|
|
|
33
35
|
"[" + JSON.stringify(importItem.export) + "] + \"";
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
var exportJs =
|
|
37
|
-
if(
|
|
38
|
-
exportJs =
|
|
39
|
-
var valueAsString = JSON.stringify(result.exports[key]);
|
|
40
|
-
valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher.bind(this));
|
|
41
|
-
return "\t" + JSON.stringify(key) + ": " + valueAsString;
|
|
42
|
-
}.bind(this)).join(",\n");
|
|
43
|
-
exportJs = "module.exports = {\n" + exportJs + "\n};";
|
|
38
|
+
var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys);
|
|
39
|
+
if (exportJs) {
|
|
40
|
+
exportJs = "module.exports = " + exportJs + ";";
|
|
44
41
|
}
|
|
45
42
|
|
|
43
|
+
|
|
46
44
|
callback(null, exportJs);
|
|
47
45
|
}.bind(this));
|
|
48
46
|
};
|
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
|
});
|
|
@@ -121,6 +134,7 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
121
134
|
|
|
122
135
|
var query = options.query;
|
|
123
136
|
var root = query.root;
|
|
137
|
+
var context = query.context;
|
|
124
138
|
var localIdentName = query.localIdentName || "[hash:base64]";
|
|
125
139
|
var localIdentRegExp = query.localIdentRegExp;
|
|
126
140
|
var forceMinimize = query.minimize;
|
|
@@ -128,18 +142,22 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
128
142
|
|
|
129
143
|
var parserOptions = {
|
|
130
144
|
root: root,
|
|
131
|
-
mode: options.mode
|
|
145
|
+
mode: options.mode,
|
|
146
|
+
url: query.url !== false,
|
|
147
|
+
import: query.import !== false
|
|
132
148
|
};
|
|
133
149
|
|
|
134
150
|
var pipeline = postcss([
|
|
135
151
|
localByDefault({
|
|
136
152
|
mode: options.mode,
|
|
137
153
|
rewriteUrl: function(global, url) {
|
|
138
|
-
if(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
154
|
+
if(parserOptions.url){
|
|
155
|
+
if(!loaderUtils.isUrlRequest(url, root)) {
|
|
156
|
+
return url;
|
|
157
|
+
}
|
|
158
|
+
if(global) {
|
|
159
|
+
return loaderUtils.urlToRequest(url, root);
|
|
160
|
+
}
|
|
143
161
|
}
|
|
144
162
|
return url;
|
|
145
163
|
}
|
|
@@ -149,7 +167,9 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
|
|
|
149
167
|
modulesScope({
|
|
150
168
|
generateScopedName: function(exportName) {
|
|
151
169
|
return getLocalIdent(options.loaderContext, localIdentName, exportName, {
|
|
152
|
-
regExp: localIdentRegExp
|
|
170
|
+
regExp: localIdentRegExp,
|
|
171
|
+
hashPrefix: query.hashPrefix || "",
|
|
172
|
+
context: context
|
|
153
173
|
});
|
|
154
174
|
}
|
|
155
175
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"author": "Tobias Koppers @sokra",
|
|
5
5
|
"description": "css loader module for webpack",
|
|
6
6
|
"dependencies": {
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"object-assign": "^4.0.1",
|
|
11
11
|
"lodash.camelcase": "^3.0.1",
|
|
12
12
|
"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
|
|
13
|
+
"postcss-modules-extract-imports": "^1.0.0",
|
|
14
|
+
"postcss-modules-local-by-default": "^1.0.1",
|
|
15
|
+
"postcss-modules-scope": "^1.0.0",
|
|
16
16
|
"postcss-modules-values": "^1.1.0",
|
|
17
17
|
"source-list-map": "^0.1.4"
|
|
18
18
|
},
|