Skip to content

docs: update #1331

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 2 commits into from
Jul 14, 2021
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
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ module.exports = {
Type: `Boolean|Object`
Default: `true`

Enables/Disables handling the CSS functions `url` and `image-set`. If set to `false`, `css-loader` will not parse any paths specified in `url` or `image-set`. A function can also be passed to control this behavior dynamically based on the path to the asset. Starting with version [4.0.0](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#400-2020-07-25), absolute paths are parsed based on the server root.
Allow to enable/disables handling the CSS functions `url` and `image-set`.
If set to `false`, `css-loader` will not parse any paths specified in `url` or `image-set`.
A function can also be passed to control this behavior dynamically based on the path to the asset.
Starting with version [4.0.0](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#400-2020-07-25), absolute paths are parsed based on the server root.

Examples resolutions:

Expand Down Expand Up @@ -203,7 +206,7 @@ module.exports = {
Type: `Boolean|Object`
Default: `true`

Enables/Disables `@import` at-rules handling.
Allows to enables/disables `@import` at-rules handling.
Control `@import` resolving. Absolute urls in `@import` will be moved in runtime code.

Examples resolutions:
Expand Down Expand Up @@ -335,9 +338,15 @@ This may change in the future when the module system (i. e. webpack) supports lo
### `modules`

Type: `Boolean|String|Object`
Default: based on filename, `true` for all files matching `/\.module\.\w+$/i.test(filename)` regular expression, more information you can read [here](https://github.com/webpack-contrib/css-loader#auto)
Default: `undefined`

Allows to enable/disable CSS Modules or ICSS and setup configuration:

Enables/Disables CSS Modules and their configuration.
- `undefined` - enable CSS modules for all files matching `/\.module\.\w+$/i.test(filename)` and `/\.icss\.\w+$/i.test(filename)` regexp.
- `true` - enable CSS modules for all files.
- `false` - disables CSS Modules for all files.
- `string` - disables CSS Modules for all files and set the `mode` option, more information you can read [here](https://github.com/webpack-contrib/css-loader#mode)
- `object` - enable CSS modules for all files, if `modules.auto` option is not specified, otherwise the `modules.auto` option will determine whether if it is CSS modules or not, more information you can read [here](https://github.com/webpack-contrib/css-loader#auto)

The `modules` option enables/disables the **[CSS Modules](https://github.com/css-modules/css-modules)** specification and setup basic behaviour.

Expand Down Expand Up @@ -598,9 +607,17 @@ module.exports = {
##### `auto`

Type: `Boolean|RegExp|Function`
Default: `'true'`
Default: `undefined`

Allows auto enable CSS modules/ICSS based on filename when `modules` option is object.

Possible values:

Allows auto enable CSS modules based on filename.
- `undefined` - enable CSS modules for all files.
- `true` - enable CSS modules for all files matching `/\.module\.\w+$/i.test(filename)` and `/\.icss\.\w+$/i.test(filename)` regexp.
- `false` - disables CSS Modules.
- `RegExp` - enable CSS modules for all files matching `/RegExp/i.test(filename)` regexp.
- `function` - enable CSS Modules for files based on the filename satisfying your filter function check.

###### `Boolean`

Expand Down
8 changes: 4 additions & 4 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"additionalProperties": false,
"properties": {
"url": {
"description": "Enables/Disables 'url'/'image-set' functions handling (https://github.com/webpack-contrib/css-loader#url).",
"description": "Allow to enable/disables handling the CSS functions `url` and `image-set` (https://github.com/webpack-contrib/css-loader#url).",
"anyOf": [
{
"type": "boolean"
Expand All @@ -20,7 +20,7 @@
]
},
"import": {
"description": "Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import).",
"description": "Allows to enables/disables `@import` at-rules handling (https://github.com/webpack-contrib/css-loader#import).",
"anyOf": [
{
"type": "boolean"
Expand Down Expand Up @@ -51,7 +51,7 @@
]
},
"modules": {
"description": "Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).",
"description": "Allows to enable/disable CSS Modules or ICSS and setup configuration (https://github.com/webpack-contrib/css-loader#modules).",
"anyOf": [
{
"type": "boolean"
Expand Down Expand Up @@ -160,7 +160,7 @@
]
},
"sourceMap": {
"description": "Enables/Disables generation of source maps (https://github.com/webpack-contrib/css-loader#sourcemap).",
"description": "Allows to enable/disable source maps (https://github.com/webpack-contrib/css-loader#sourcemap).",
"type": "boolean"
},
"esModule": {
Expand Down
36 changes: 18 additions & 18 deletions test/__snapshots__/validate-options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`validate options should throw an error on the "import" option with "()
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.import should be one of these:
boolean | object { filter?, loaders? }
-> Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import).
-> Allows to enables/disables \`@import\` at-rules handling (https://github.com/webpack-contrib/css-loader#import).
Details:
* options.import should be a boolean.
* options.import should be an object:
Expand All @@ -21,7 +21,7 @@ exports[`validate options should throw an error on the "import" option with "[]"
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.import should be one of these:
boolean | object { filter?, loaders? }
-> Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import).
-> Allows to enables/disables \`@import\` at-rules handling (https://github.com/webpack-contrib/css-loader#import).
Details:
* options.import should be a boolean.
* options.import should be an object:
Expand All @@ -37,7 +37,7 @@ exports[`validate options should throw an error on the "import" option with "{"l
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.import should be one of these:
boolean | object { filter?, loaders? }
-> Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import).
-> Allows to enables/disables \`@import\` at-rules handling (https://github.com/webpack-contrib/css-loader#import).
Details:
* options.import.loaders should be one of these:
boolean | string | integer
Expand All @@ -58,7 +58,7 @@ exports[`validate options should throw an error on the "import" option with "tru
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.import should be one of these:
boolean | object { filter?, loaders? }
-> Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import).
-> Allows to enables/disables \`@import\` at-rules handling (https://github.com/webpack-contrib/css-loader#import).
Details:
* options.import should be a boolean.
* options.import should be an object:
Expand All @@ -69,7 +69,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
-> Allows to enable/disable CSS Modules or ICSS and setup configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.auto should be one of these:
RegExp | function | boolean
Expand Down Expand Up @@ -127,7 +127,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
-> Allows to enable/disable CSS Modules or ICSS and setup configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.localIdentRegExp should be one of these:
non-empty string | RegExp
Expand All @@ -141,7 +141,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
-> Allows to enable/disable CSS Modules or ICSS and setup configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.mode should be one of these:
\\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | function
Expand All @@ -156,7 +156,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
-> Allows to enable/disable CSS Modules or ICSS and setup configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.mode should be one of these:
\\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | function
Expand All @@ -171,7 +171,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
-> Allows to enable/disable CSS Modules or ICSS and setup configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.mode should be one of these:
\\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | function
Expand All @@ -186,7 +186,7 @@ exports[`validate options should throw an error on the "modules" option with "{"
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
-> Allows to enable/disable CSS Modules or ICSS and setup configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules.mode should be one of these:
\\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | function
Expand All @@ -207,7 +207,7 @@ exports[`validate options should throw an error on the "modules" option with "gl
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
-> Allows to enable/disable CSS Modules or ICSS and setup configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules should be a boolean.
* options.modules should be one of these:
Expand All @@ -220,7 +220,7 @@ exports[`validate options should throw an error on the "modules" option with "lo
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
-> Allows to enable/disable CSS Modules or ICSS and setup configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules should be a boolean.
* options.modules should be one of these:
Expand All @@ -233,7 +233,7 @@ exports[`validate options should throw an error on the "modules" option with "pu
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
-> Allows to enable/disable CSS Modules or ICSS and setup configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules should be a boolean.
* options.modules should be one of these:
Expand All @@ -246,7 +246,7 @@ exports[`validate options should throw an error on the "modules" option with "tr
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.modules should be one of these:
boolean | \\"local\\" | \\"global\\" | \\"pure\\" | \\"icss\\" | object { auto?, mode?, localIdentName?, localIdentContext?, localIdentHashSalt?, localIdentHashFunction?, localIdentHashDigest?, localIdentHashDigestLength?, localIdentRegExp?, getLocalIdent?, namedExport?, exportGlobals?, exportLocalsConvention?, exportOnlyLocals? }
-> Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).
-> Allows to enable/disable CSS Modules or ICSS and setup configuration (https://github.com/webpack-contrib/css-loader#modules).
Details:
* options.modules should be a boolean.
* options.modules should be one of these:
Expand All @@ -258,7 +258,7 @@ exports[`validate options should throw an error on the "modules" option with "tr
exports[`validate options should throw an error on the "sourceMap" option with "true" value 1`] = `
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.sourceMap should be a boolean.
-> Enables/Disables generation of source maps (https://github.com/webpack-contrib/css-loader#sourcemap)."
-> Allows to enable/disable source maps (https://github.com/webpack-contrib/css-loader#sourcemap)."
`;

exports[`validate options should throw an error on the "unknown" option with "/test/" value 1`] = `
Expand Down Expand Up @@ -313,7 +313,7 @@ exports[`validate options should throw an error on the "url" option with "() =>
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.url should be one of these:
boolean | object { filter? }
-> Enables/Disables 'url'/'image-set' functions handling (https://github.com/webpack-contrib/css-loader#url).
-> Allow to enable/disables handling the CSS functions \`url\` and \`image-set\` (https://github.com/webpack-contrib/css-loader#url).
Details:
* options.url should be a boolean.
* options.url should be an object:
Expand All @@ -324,7 +324,7 @@ exports[`validate options should throw an error on the "url" option with "[]" va
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.url should be one of these:
boolean | object { filter? }
-> Enables/Disables 'url'/'image-set' functions handling (https://github.com/webpack-contrib/css-loader#url).
-> Allow to enable/disables handling the CSS functions \`url\` and \`image-set\` (https://github.com/webpack-contrib/css-loader#url).
Details:
* options.url should be a boolean.
* options.url should be an object:
Expand All @@ -346,7 +346,7 @@ exports[`validate options should throw an error on the "url" option with "true"
"Invalid options object. CSS Loader has been initialized using an options object that does not match the API schema.
- options.url should be one of these:
boolean | object { filter? }
-> Enables/Disables 'url'/'image-set' functions handling (https://github.com/webpack-contrib/css-loader#url).
-> Allow to enable/disables handling the CSS functions \`url\` and \`image-set\` (https://github.com/webpack-contrib/css-loader#url).
Details:
* options.url should be a boolean.
* options.url should be an object:
Expand Down