Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
var path = require("path");
var loaderUtils = require("loader-utils");
var camelCase = require("lodash.camelcase");
var processCss = require("./processCss");
var getImportPrefix = require("./getImportPrefix");

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

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

var exportJs = "";
if(Object.keys(result.exports).length > 0) {
exportJs = Object.keys(result.exports).map(function(key) {
var boundImportItemMatcher = importItemMatcher.bind(this);
exportJs = Object.keys(result.exports).reduce(function(res, key) {
var valueAsString = JSON.stringify(result.exports[key]);
valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher.bind(this));
return "\t" + JSON.stringify(key) + ": " + valueAsString;
}.bind(this)).join(",\n");
valueAsString = valueAsString.replace(result.importItemRegExpG, boundImportItemMatcher);
res.push("\t" + JSON.stringify(key) + ": " + valueAsString);
if (camelCaseKeys) {
res.push("\t" + JSON.stringify(camelCase(key)) + ": " + valueAsString);
}
return res;
}, []).join(",\n");
exportJs = "exports.locals = {\n" + exportJs + "\n};";
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"cssnano": ">=2.6.1 <4",
"loader-utils": "~0.2.2",
"object-assign": "^4.0.1",
"lodash.camelcase": "^3.0.1",
"postcss": "^5.0.6",
"postcss-modules-extract-imports": "1.0.0-beta2",
"postcss-modules-local-by-default": "1.0.0-beta1",
Expand Down
19 changes: 19 additions & 0 deletions test/camelCaseTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*globals describe */

var test = require("./helpers").test;

describe("camelCase", function() {
var css = ".btn-info { color: blue; }";
var exports = {
with: [
[1, "._38r5hlPyrqKLodJwWOdM1k { color: blue; }", ""]
],
without: [
[1, "._38r5hlPyrqKLodJwWOdM1k { color: blue; }", ""]
]
};
exports.with.locals = {'btn-info': '_38r5hlPyrqKLodJwWOdM1k'};
exports.without.locals = {btnInfo: '_38r5hlPyrqKLodJwWOdM1k', 'btn-info': '_38r5hlPyrqKLodJwWOdM1k'};
test("with", css, exports.with, "?modules");
test("without", css, exports.without, "?modules&camelCase");
});