Skip to content

refactor: the modules.localsConvention option was renamed to the modules.exportLocalsConvention option #1120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
122 changes: 61 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ module.exports = {
context: path.resolve(__dirname, 'src'),
localIdentHashPrefix: 'my-custom-hash',
namedExport: true,
localsConvention: 'camelCase',
exportLocalsConvention: 'camelCase',
exportOnlyLocals: false,
},
},
Expand Down Expand Up @@ -758,55 +758,6 @@ module.exports = {
};
```

##### `localsConvention`

Type: `String`
Default: `'asIs'`

Style of exported classnames.

By default, the exported JSON keys mirror the class names (i.e `asIs` value).

| Name | Type | Description |
| :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- |
| **`'asIs'`** | `{String}` | Class names will be exported as is. |
| **`'camelCase'`** | `{String}` | Class names will be camelized, the original class name will not to be removed from the locals |
| **`'camelCaseOnly'`** | `{String}` | Class names will be camelized, the original class name will be removed from the locals |
| **`'dashes'`** | `{String}` | Only dashes in class names will be camelized |
| **`'dashesOnly'`** | `{String}` | Dashes in class names will be camelized, the original class name will be removed from the locals |

**file.css**

```css
.class-name {
}
```

**file.js**

```js
import { className } from 'file.css';
```

**webpack.config.js**

```js
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
loader: 'css-loader',
options: {
mode: 'local',
localsConvention: 'camelCase',
},
},
],
},
};
```

##### `localIdentContext`

Type: `String`
Expand Down Expand Up @@ -861,14 +812,11 @@ module.exports = {
};
```

##### `getLocalIdent`
##### `localIdentRegExp`

Type: `Function`
Type: `String|RegExp`
Default: `undefined`

You can also specify the absolute path to your custom `getLocalIdent` function to generate classname based on a different schema.
By default we use built-in function to generate a classname.

**webpack.config.js**

```js
Expand All @@ -880,9 +828,7 @@ module.exports = {
loader: 'css-loader',
options: {
modules: {
getLocalIdent: (context, localIdentName, localName, options) => {
return 'whatever_random_class_name';
},
localIdentRegExp: /page-(.*)\.css/i,
},
},
},
Expand All @@ -891,11 +837,14 @@ module.exports = {
};
```

##### `localIdentRegExp`
##### `getLocalIdent`

Type: `String|RegExp`
Type: `Function`
Default: `undefined`

You can also specify the absolute path to your custom `getLocalIdent` function to generate classname based on a different schema.
By default we use built-in function to generate a classname.

**webpack.config.js**

```js
Expand All @@ -907,7 +856,9 @@ module.exports = {
loader: 'css-loader',
options: {
modules: {
localIdentRegExp: /page-(.*)\.css/i,
getLocalIdent: (context, localIdentName, localName, options) => {
return 'whatever_random_class_name';
},
},
},
},
Expand Down Expand Up @@ -968,6 +919,55 @@ module.exports = {
};
```

##### `exportlocalsConvention`

Type: `String`
Default: `'asIs'`

Style of exported class names.

By default, the exported JSON keys mirror the class names (i.e `asIs` value).

| Name | Type | Description |
| :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- |
| **`'asIs'`** | `{String}` | Class names will be exported as is. |
| **`'camelCase'`** | `{String}` | Class names will be camelized, the original class name will not to be removed from the locals |
| **`'camelCaseOnly'`** | `{String}` | Class names will be camelized, the original class name will be removed from the locals |
| **`'dashes'`** | `{String}` | Only dashes in class names will be camelized |
| **`'dashesOnly'`** | `{String}` | Dashes in class names will be camelized, the original class name will be removed from the locals |

**file.css**

```css
.class-name {
}
```

**file.js**

```js
import { className } from 'file.css';
```

**webpack.config.js**

```js
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
loader: 'css-loader',
options: {
mode: 'local',
localsConvention: 'camelCase',
},
},
],
},
};
```

##### `exportOnlyLocals`

Type: `Boolean`
Expand Down
10 changes: 5 additions & 5 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@
}
]
},
"localsConvention": {
"namedExport": {
"description": "Use the named export ES modules.",
"type": "boolean"
},
"exportLocalsConvention": {
"description": "Style of exported classnames (https://github.com/webpack-contrib/css-loader#localsconvention).",
"enum": [
"asIs",
Expand All @@ -105,10 +109,6 @@
"dashesOnly"
]
},
"namedExport": {
"description": "Use the named export ES modules.",
"type": "boolean"
},
"exportOnlyLocals": {
"description": "Export only locals (https://github.com/webpack-contrib/css-loader#exportonlylocals).",
"type": "boolean"
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ function getModulesOptions(rawOptions, loaderContext) {
// eslint-disable-next-line no-undefined
localIdentRegExp: undefined,
getLocalIdent,
localsConvention: 'asIs',
namedExport: false,
exportLocalsConvention: 'asIs',
exportOnlyLocals: false,
};

Expand Down Expand Up @@ -440,7 +440,7 @@ function getExportCode(exports, icssReplacements, options) {
};

for (const { name, value } of exports) {
switch (options.modules.localsConvention) {
switch (options.modules.exportLocalsConvention) {
case 'camelCase': {
addExportToLocalsCode(name, value);

Expand Down
Loading