Skip to content

Commit d1aa291

Browse files
committed
Merge pull request webpack-contrib#149 from nkt/camelcased-keys
Added camelCase option
2 parents 909f8e6 + 4e6bd42 commit d1aa291

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

lib/loader.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
var path = require("path");
66
var loaderUtils = require("loader-utils");
7+
var camelCase = require("lodash.camelcase");
78
var processCss = require("./processCss");
89
var getImportPrefix = require("./getImportPrefix");
910

@@ -14,6 +15,7 @@ module.exports = function(content, map) {
1415
var query = loaderUtils.parseQuery(this.query);
1516
var root = query.root;
1617
var moduleMode = query.modules || query.module;
18+
var camelCaseKeys = query.camelCase || query.camelcase;
1719

1820
if(map !== null && typeof map !== "string") {
1921
map = JSON.stringify(map);
@@ -82,11 +84,16 @@ module.exports = function(content, map) {
8284

8385
var exportJs = "";
8486
if(Object.keys(result.exports).length > 0) {
85-
exportJs = Object.keys(result.exports).map(function(key) {
87+
var boundImportItemMatcher = importItemMatcher.bind(this);
88+
exportJs = Object.keys(result.exports).reduce(function(res, key) {
8689
var valueAsString = JSON.stringify(result.exports[key]);
87-
valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher.bind(this));
88-
return "\t" + JSON.stringify(key) + ": " + valueAsString;
89-
}.bind(this)).join(",\n");
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);
94+
}
95+
return res;
96+
}, []).join(",\n");
9097
exportJs = "exports.locals = {\n" + exportJs + "\n};";
9198
}
9299

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"cssnano": ">=2.6.1 <4",
99
"loader-utils": "~0.2.2",
1010
"object-assign": "^4.0.1",
11+
"lodash.camelcase": "^3.0.1",
1112
"postcss": "^5.0.6",
1213
"postcss-modules-extract-imports": "1.0.0-beta2",
1314
"postcss-modules-local-by-default": "1.0.0-beta1",

test/camelCaseTest.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*globals describe */
2+
3+
var test = require("./helpers").test;
4+
5+
describe("camelCase", function() {
6+
var css = ".btn-info { color: blue; }";
7+
var exports = {
8+
with: [
9+
[1, "._38r5hlPyrqKLodJwWOdM1k { color: blue; }", ""]
10+
],
11+
without: [
12+
[1, "._38r5hlPyrqKLodJwWOdM1k { color: blue; }", ""]
13+
]
14+
};
15+
exports.with.locals = {'btn-info': '_38r5hlPyrqKLodJwWOdM1k'};
16+
exports.without.locals = {btnInfo: '_38r5hlPyrqKLodJwWOdM1k', 'btn-info': '_38r5hlPyrqKLodJwWOdM1k'};
17+
test("with", css, exports.with, "?modules");
18+
test("without", css, exports.without, "?modules&camelCase");
19+
});

0 commit comments

Comments
 (0)