Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Apr 4, 2024
1 parent 63fee36 commit d6bb67a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand All @@ -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);
```

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -1287,7 +1292,7 @@ module.exports = {
loader: "css-loader",
options: {
modules: {
exportLocalsConvention: "camel-case",
exportLocalsConvention: "camel-case-only",
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ function getModulesOptions(rawOptions, esModule, exportType, loaderContext) {
);
}

if (
/* if (
typeof exportLocalsConventionType === "string" &&
exportLocalsConventionType !== "asIs" &&
exportLocalsConventionType !== "as-is" &&
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions test/__snapshots__/modules-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
]
`;

Expand All @@ -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:",
]
`;

Expand Down

0 comments on commit d6bb67a

Please sign in to comment.