Skip to content

Commit 069dbb0

Browse files
refactor: the modules.localsConvention option was renamed to the modules.exportLocalsConvention option (#1120)
BREAKING CHANGE: the `modules.localsConvention` option was renamed to the `modules.exportLocalsConvention` option
1 parent fc04401 commit 069dbb0

File tree

6 files changed

+101
-101
lines changed

6 files changed

+101
-101
lines changed

README.md

+61-61
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ module.exports = {
534534
context: path.resolve(__dirname, 'src'),
535535
localIdentHashPrefix: 'my-custom-hash',
536536
namedExport: true,
537-
localsConvention: 'camelCase',
537+
exportLocalsConvention: 'camelCase',
538538
exportOnlyLocals: false,
539539
},
540540
},
@@ -758,55 +758,6 @@ module.exports = {
758758
};
759759
```
760760

761-
##### `localsConvention`
762-
763-
Type: `String`
764-
Default: `'asIs'`
765-
766-
Style of exported classnames.
767-
768-
By default, the exported JSON keys mirror the class names (i.e `asIs` value).
769-
770-
| Name | Type | Description |
771-
| :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- |
772-
| **`'asIs'`** | `{String}` | Class names will be exported as is. |
773-
| **`'camelCase'`** | `{String}` | Class names will be camelized, the original class name will not to be removed from the locals |
774-
| **`'camelCaseOnly'`** | `{String}` | Class names will be camelized, the original class name will be removed from the locals |
775-
| **`'dashes'`** | `{String}` | Only dashes in class names will be camelized |
776-
| **`'dashesOnly'`** | `{String}` | Dashes in class names will be camelized, the original class name will be removed from the locals |
777-
778-
**file.css**
779-
780-
```css
781-
.class-name {
782-
}
783-
```
784-
785-
**file.js**
786-
787-
```js
788-
import { className } from 'file.css';
789-
```
790-
791-
**webpack.config.js**
792-
793-
```js
794-
module.exports = {
795-
module: {
796-
rules: [
797-
{
798-
test: /\.css$/i,
799-
loader: 'css-loader',
800-
options: {
801-
mode: 'local',
802-
localsConvention: 'camelCase',
803-
},
804-
},
805-
],
806-
},
807-
};
808-
```
809-
810761
##### `localIdentContext`
811762

812763
Type: `String`
@@ -861,14 +812,11 @@ module.exports = {
861812
};
862813
```
863814

864-
##### `getLocalIdent`
815+
##### `localIdentRegExp`
865816

866-
Type: `Function`
817+
Type: `String|RegExp`
867818
Default: `undefined`
868819

869-
You can also specify the absolute path to your custom `getLocalIdent` function to generate classname based on a different schema.
870-
By default we use built-in function to generate a classname.
871-
872820
**webpack.config.js**
873821

874822
```js
@@ -880,9 +828,7 @@ module.exports = {
880828
loader: 'css-loader',
881829
options: {
882830
modules: {
883-
getLocalIdent: (context, localIdentName, localName, options) => {
884-
return 'whatever_random_class_name';
885-
},
831+
localIdentRegExp: /page-(.*)\.css/i,
886832
},
887833
},
888834
},
@@ -891,11 +837,14 @@ module.exports = {
891837
};
892838
```
893839

894-
##### `localIdentRegExp`
840+
##### `getLocalIdent`
895841

896-
Type: `String|RegExp`
842+
Type: `Function`
897843
Default: `undefined`
898844

845+
You can also specify the absolute path to your custom `getLocalIdent` function to generate classname based on a different schema.
846+
By default we use built-in function to generate a classname.
847+
899848
**webpack.config.js**
900849

901850
```js
@@ -907,7 +856,9 @@ module.exports = {
907856
loader: 'css-loader',
908857
options: {
909858
modules: {
910-
localIdentRegExp: /page-(.*)\.css/i,
859+
getLocalIdent: (context, localIdentName, localName, options) => {
860+
return 'whatever_random_class_name';
861+
},
911862
},
912863
},
913864
},
@@ -968,6 +919,55 @@ module.exports = {
968919
};
969920
```
970921

922+
##### `exportlocalsConvention`
923+
924+
Type: `String`
925+
Default: `'asIs'`
926+
927+
Style of exported class names.
928+
929+
By default, the exported JSON keys mirror the class names (i.e `asIs` value).
930+
931+
| Name | Type | Description |
932+
| :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- |
933+
| **`'asIs'`** | `{String}` | Class names will be exported as is. |
934+
| **`'camelCase'`** | `{String}` | Class names will be camelized, the original class name will not to be removed from the locals |
935+
| **`'camelCaseOnly'`** | `{String}` | Class names will be camelized, the original class name will be removed from the locals |
936+
| **`'dashes'`** | `{String}` | Only dashes in class names will be camelized |
937+
| **`'dashesOnly'`** | `{String}` | Dashes in class names will be camelized, the original class name will be removed from the locals |
938+
939+
**file.css**
940+
941+
```css
942+
.class-name {
943+
}
944+
```
945+
946+
**file.js**
947+
948+
```js
949+
import { className } from 'file.css';
950+
```
951+
952+
**webpack.config.js**
953+
954+
```js
955+
module.exports = {
956+
module: {
957+
rules: [
958+
{
959+
test: /\.css$/i,
960+
loader: 'css-loader',
961+
options: {
962+
mode: 'local',
963+
localsConvention: 'camelCase',
964+
},
965+
},
966+
],
967+
},
968+
};
969+
```
970+
971971
##### `exportOnlyLocals`
972972

973973
Type: `Boolean`

src/options.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@
9595
}
9696
]
9797
},
98-
"localsConvention": {
98+
"namedExport": {
99+
"description": "Use the named export ES modules.",
100+
"type": "boolean"
101+
},
102+
"exportLocalsConvention": {
99103
"description": "Style of exported classnames (https://github.com/webpack-contrib/css-loader#localsconvention).",
100104
"enum": [
101105
"asIs",
@@ -105,10 +109,6 @@
105109
"dashesOnly"
106110
]
107111
},
108-
"namedExport": {
109-
"description": "Use the named export ES modules.",
110-
"type": "boolean"
111-
},
112112
"exportOnlyLocals": {
113113
"description": "Export only locals (https://github.com/webpack-contrib/css-loader#exportonlylocals).",
114114
"type": "boolean"

src/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ function getModulesOptions(rawOptions, loaderContext) {
127127
// eslint-disable-next-line no-undefined
128128
localIdentRegExp: undefined,
129129
getLocalIdent,
130-
localsConvention: 'asIs',
131130
namedExport: false,
131+
exportLocalsConvention: 'asIs',
132132
exportOnlyLocals: false,
133133
};
134134

@@ -440,7 +440,7 @@ function getExportCode(exports, icssReplacements, options) {
440440
};
441441

442442
for (const { name, value } of exports) {
443-
switch (options.modules.localsConvention) {
443+
switch (options.modules.exportLocalsConvention) {
444444
case 'camelCase': {
445445
addExportToLocalsCode(name, value);
446446

0 commit comments

Comments
 (0)