From 9852aa6921d1bceb2da630b3429e9ab51fdb4fd9 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Thu, 4 Apr 2024 15:58:19 +0300 Subject: [PATCH] docs: update --- README.md | 31 +++++++++++-------- src/utils.js | 4 +-- .../__snapshots__/modules-option.test.js.snap | 8 ++--- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index a62a9c01..91396515 100644 --- a/README.md +++ b/README.md @@ -1138,21 +1138,13 @@ Type: type namedExport = boolean; ``` -Default: `false` +Default: Depends on the value of the `esModule` option. If the value of the `esModule` options is `true`, this value will also be `true`, otherwise it will be `false`. Enables/disables ES modules named export for locals. > **Warning** > -> Names of locals are converted to camelcase, i.e. the `exportLocalsConvention` option has -> `camelCaseOnly` value by default. You can set this back to any other valid option but selectors -> which are not valid JavaScript identifiers may run into problems which do not implement the entire -> modules specification. - -> **Warning** -> -> It is not allowed to use JavaScript reserved words in css class names unless -> `exportLocalsConvention` is `"as-is"`. +> It is not allowed to use JavaScript reserved words in css class names unless `exportLocalsConvention` is `"as-is"`. **styles.css** @@ -1170,8 +1162,10 @@ Enables/disables ES modules named export for locals. ```js import * as styles from "./styles.css"; +// If using `exportLocalsConvention: "camel-case-only"`: console.log(styles.fooBaz, styles.bar); -// or if using `exportLocalsConvention: "as-is"`: + +// If using `exportLocalsConvention: "as-is"`: console.log(styles["foo-baz"], styles.bar); ``` @@ -1247,7 +1241,18 @@ type exportLocalsConvention = | ((name: string) => string); ``` -Default: based on the `modules.namedExport` option value, if `true` - `camelCaseOnly`, otherwise `as-is` +Default: Depends on the value of the `modules.namedExport` option, if `true` - `as-is`, otherwise `camel-case-only`. + +> **Warning** +> +> Names of locals are converted to camelcase when the named export is `false`, i.e. the `exportLocalsConvention` option has +> `camelCaseOnly` value by default. You can set this back to any other valid option but selectors +> which are not valid JavaScript identifiers may run into problems which do not implement the entire +> modules specification. + +> **Warning** +> +> **You need to disable `modules.namedExport` if you want to use `'camel-case'` or `'dashes'` value.** Style of exported class names. @@ -1287,7 +1292,7 @@ module.exports = { loader: "css-loader", options: { modules: { - exportLocalsConvention: "camel-case", + exportLocalsConvention: "camel-case-only", }, }, }, diff --git a/src/utils.js b/src/utils.js index f1e32f54..f28f62af 100644 --- a/src/utils.js +++ b/src/utils.js @@ -647,7 +647,7 @@ function getModulesOptions(rawOptions, esModule, exportType, loaderContext) { ); } - if ( + /* if ( typeof exportLocalsConventionType === "string" && exportLocalsConventionType !== "asIs" && exportLocalsConventionType !== "as-is" && @@ -659,7 +659,7 @@ function getModulesOptions(rawOptions, esModule, exportType, loaderContext) { throw new Error( 'The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "as-is", "camel-case-only" or "dashes-only"', ); - } + }*/ } return modulesOptions; diff --git a/test/__snapshots__/modules-option.test.js.snap b/test/__snapshots__/modules-option.test.js.snap index 371e5776..0506a8e9 100644 --- a/test/__snapshots__/modules-option.test.js.snap +++ b/test/__snapshots__/modules-option.test.js.snap @@ -2551,8 +2551,8 @@ exports[`"modules" option should throw an error when class has unsupported name exports[`"modules" option should throw an error when the "namedExport" is enabled and the "exportLocalsConvention" options has not "camelCaseOnly" value: errors 1`] = ` [ - "ModuleBuildError: Module build failed (from \`replaced original path\`): -Error: The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "as-is", "camel-case-only" or "dashes-only"", + "ModuleParseError: Module parse failed: Unexpected keyword 'class' (11:11) +File was processed with these loaders:", ] `; @@ -2578,8 +2578,8 @@ exports[`"modules" option should throw error when the "exportLocalsConvention" f exports[`"modules" option should throw error with composes when the "namedExport" is enabled and "exportLocalsConvention" options has invalid value: errors 1`] = ` [ - "ModuleBuildError: Module build failed (from \`replaced original path\`): -Error: The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "as-is", "camel-case-only" or "dashes-only"", + "ModuleParseError: Module parse failed: Unexpected token (30:18) +File was processed with these loaders:", ] `;