Skip to content

Commit 5126cff

Browse files
author
Nikita Gusakov
committed
Added camelCase option
1 parent 909f8e6 commit 5126cff

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/loader.js

+4-1
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);
@@ -85,7 +87,8 @@ module.exports = function(content, map) {
8587
exportJs = Object.keys(result.exports).map(function(key) {
8688
var valueAsString = JSON.stringify(result.exports[key]);
8789
valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher.bind(this));
88-
return "\t" + JSON.stringify(key) + ": " + valueAsString;
90+
var exportKey = camelCaseKeys ? camelCase(key) : key;
91+
return "\t" + JSON.stringify(exportKey) + ": " + valueAsString;
8992
}.bind(this)).join(",\n");
9093
exportJs = "exports.locals = {\n" + exportJs + "\n};";
9194
}

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'};
17+
test("with", css, exports.with, "?modules");
18+
test("without", css, exports.without, "?modules&camelCase");
19+
});

0 commit comments

Comments
 (0)