Skip to content

Commit

Permalink
refactor: the modules.localsConvention option was renamed to the `m…
Browse files Browse the repository at this point in the history
…odules.exportLocalsConvention` option (#1120)

BREAKING CHANGE: the `modules.localsConvention` option was renamed to the `modules.exportLocalsConvention` option
  • Loading branch information
evilebottnawi committed Jul 21, 2020
1 parent fc04401 commit 069dbb0
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 101 deletions.
122 changes: 61 additions & 61 deletions README.md
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
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
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

0 comments on commit 069dbb0

Please sign in to comment.