Skip to content

Commit 3f78361

Browse files
joschajoshwiens
authored andcommitted
feat: allow removal of original class name (#445)
* feat: allow removal of original class name * add comment for 1.0.0 * docs: move table * docs: consistency
1 parent 17faa31 commit 3f78361

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,15 @@ You can also disable or enforce minification with the `minimize` query parameter
398398

399399
By default, the exported JSON keys mirror the class names. If you want to camelize class names (useful in JS), pass the query parameter `camelCase` to css-loader.
400400

401+
#### Possible Options
402+
403+
|Option|Description|
404+
|:----:|:--------|
405+
|**`true`**|Class names will be camelized|
406+
|**`'dashes'`**|Only dashes in class names will be camelized|
407+
|**`'only'`** |Class names will be camelized, the original class name will be removed from the locals|
408+
|**`'dashesOnly'`**|Dashes in class names will be camelized, the original class name will be removed from the locals|
409+
401410
**webpack.config.js**
402411
```js
403412
{

lib/compile-exports.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ module.exports = function compileExports(result, importItemMatcher, camelCaseKey
1717
function addEntry(k) {
1818
res.push("\t" + JSON.stringify(k) + ": " + valueAsString);
1919
}
20-
addEntry(key);
20+
if (camelCaseKeys !== 'only' && camelCaseKeys !== 'dashesOnly') {
21+
addEntry(key);
22+
}
2123

2224
var targetKey;
23-
if (camelCaseKeys === true) {
25+
if (camelCaseKeys === true || camelCaseKeys === 'only') {
2426
targetKey = camelCase(key);
2527
if (targetKey !== key) {
2628
addEntry(targetKey);
2729
}
28-
} else if (camelCaseKeys === 'dashes') {
30+
} else if (camelCaseKeys === 'dashes' || camelCaseKeys === 'dashesOnly') {
2931
targetKey = dashesCamelCase(key);
3032
if (targetKey !== key) {
3133
addEntry(targetKey);

test/camelCaseTest.js

+12
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@ describe("camelCase", function() {
1414
],
1515
dashes: [
1616
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
17+
],
18+
withoutOnly: [
19+
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
20+
],
21+
dashesOnly: [
22+
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
1723
]
1824
};
1925
exports.with.locals = {'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
2026
exports.without.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
2127
exports.dashes.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
28+
exports.withoutOnly.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB'};
29+
exports.dashesOnly.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB'};
2230
test("with", css, exports.with, "?modules");
2331
test("without", css, exports.without, "?modules&camelCase");
2432
test("dashes", css, exports.dashes, "?modules&camelCase=dashes");
33+
// Remove this option in v1.0.0 and make the removal of the original classname the default behaviour. See #440.
34+
test("withoutOnly", css, exports.withoutOnly, "?modules&camelCase=only");
35+
// Remove this option in v1.0.0 and make the removal of the original classname the default behaviour. See #440.
36+
test("dashesOnly", css, exports.dashesOnly, "?modules&camelCase=dashesOnly");
2537

2638
testRaw("withoutRaw", '.a {}', 'exports.locals = {\n\t"a": "_1buUQJccBRS2-2i27LCoDf"\n};', "?modules&camelCase");
2739
testRaw("dashesRaw", '.a {}', 'exports.locals = {\n\t"a": "_1buUQJccBRS2-2i27LCoDf"\n};', "?modules&camelCase=dashes");

0 commit comments

Comments
 (0)