Skip to content

Commit

Permalink
refactor: improve schema options (#1123)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Jul 22, 2020
1 parent 58b4b98 commit c153fe6
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 58 deletions.
68 changes: 34 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ module.exports = {
Type: `Boolean|RegExp|Function`
Default: `'true'`

Allows auto enable css modules based on filename.
Allows auto enable CSS modules based on filename.

###### `Boolean`

Expand Down Expand Up @@ -694,39 +694,12 @@ module.exports = {
};
```

##### `exportGlobals`

Type: `Boolean`
Default: `false`

Allow `css-loader` to export names from global class or id, so you can use that as local name.

**webpack.config.js**

```js
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
loader: 'css-loader',
options: {
modules: {
exportGlobals: true,
},
},
},
],
},
};
```

##### `localIdentName`

Type: `String`
Default: `'[hash:base64]'`

You can configure the generated ident with the `localIdentName` option.
Allows to configure the generated local ident name.
See [loader-utils's documentation](https://github.com/webpack/loader-utils#interpolatename) for more information on options.

Recommendations:
Expand Down Expand Up @@ -763,7 +736,7 @@ module.exports = {
Type: `String`
Default: `compiler.context`

Allow to redefine basic loader context for local ident name.
Allows to redefine basic loader context for local ident name.

**webpack.config.js**

Expand All @@ -790,7 +763,7 @@ module.exports = {
Type: `String`
Default: `undefined`

Allow to add custom hash to generate more unique classes.
Allows to add custom hash to generate more unique classes.

**webpack.config.js**

Expand Down Expand Up @@ -842,7 +815,7 @@ module.exports = {
Type: `Function`
Default: `undefined`

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

**webpack.config.js**
Expand Down Expand Up @@ -872,8 +845,8 @@ module.exports = {
Type: `Boolean`
Default: `false`

Enable/disable ES modules named export for css classes.
Names of exported classes are converted to camelCase.
Enables/disables ES modules named export for locals.
Names of locals are converted to camelCase.

> i It is not allowed to use JavaScript reserved words in css class names
Expand Down Expand Up @@ -919,6 +892,33 @@ module.exports = {
};
```

##### `exportGlobals`

Type: `Boolean`
Default: `false`

Allow `css-loader` to export names from global class or id, so you can use that as local name.

**webpack.config.js**

```js
module.exports = {
module: {
rules: [
{
test: /\.css$/i,
loader: 'css-loader',
options: {
modules: {
exportGlobals: true,
},
},
},
],
},
};
```

##### `exportlocalsConvention`

Type: `String`
Expand Down
16 changes: 12 additions & 4 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"additionalProperties": false,
"properties": {
"auto": {
"description": "Allows auto enable CSS modules based on filename (https://github.com/webpack-contrib/css-loader#auto).",
"anyOf": [
{
"instanceof": "RegExp"
Expand All @@ -50,6 +51,7 @@
]
},
"mode": {
"description": "Setup `mode` option (https://github.com/webpack-contrib/css-loader#mode).",
"anyOf": [
{
"enum": ["local", "global", "pure"]
Expand All @@ -59,22 +61,23 @@
}
]
},
"exportGlobals": {
"type": "boolean"
},
"localIdentName": {
"description": "Allows to configure the generated local ident name (https://github.com/webpack-contrib/css-loader#localidentname).",
"type": "string",
"minLength": 1
},
"localIdentContext": {
"description": "Allows to redefine basic loader context for local ident name (https://github.com/webpack-contrib/css-loader#localidentcontext).",
"type": "string",
"minLength": 1
},
"localIdentHashPrefix": {
"description": "Allows to add custom hash to generate more unique classes (https://github.com/webpack-contrib/css-loader#localidenthashprefix).",
"type": "string",
"minLength": 1
},
"localIdentRegExp": {
"description": "Allows to specify custom RegExp for local ident name (https://github.com/webpack-contrib/css-loader#localidentregexp).",
"anyOf": [
{
"type": "string",
Expand All @@ -86,10 +89,15 @@
]
},
"getLocalIdent": {
"description": "Allows to specify a function to generate the classname (https://github.com/webpack-contrib/css-loader#getlocalident).",
"instanceof": "Function"
},
"namedExport": {
"description": "Use the named export ES modules.",
"description": "Enables/disables ES modules named export for locals (https://github.com/webpack-contrib/css-loader#namedexport).",
"type": "boolean"
},
"exportGlobals": {
"description": "Allows to export names from global class or id, so you can use that as local name (https://github.com/webpack-contrib/css-loader#exportglobals).",
"type": "boolean"
},
"exportLocalsConvention": {
Expand Down
Loading

0 comments on commit c153fe6

Please sign in to comment.