diff --git a/README.md b/README.md index 1b658f8..d1cf037 100644 --- a/README.md +++ b/README.md @@ -38,13 +38,14 @@ module.exports = { ## Options -| Name | Type | Description | -| :-------------------------------------: | :---------: | :------------------------------------------------------------------------------: | -| **[`banner`](#banner)** | `{String}` | To add a 'banner' prefix to each generated `*.d.ts` file | -| **[`formatter`](#formatter)** | `{String}` | Formats the generated `*.d.ts` file with specified formatter, eg. `prettier` | -| **[`eol`](#eol)** | `{String}` | Newline character to be used in generated `*.d.ts` files | -| **[`verifyOnly`](#verifyOnly)** | `{Boolean}` | Validate generated `*.d.ts` files and fail if an update is needed (useful in CI) | -| **[`disableLocalsExport`](#disableLocalsExport)** | `{Boolean}` | Disable the use of locals export. | +| Name | Type | Description | +| :-----------------------------------------------: | :---------: | :----------------------------------------------------------: | +| **[`banner`](#banner)** | `{String}` | To add a 'banner' prefix to each generated `*.d.ts` file | +| **[`formatter`](#formatter)** | `{String}` | Formats the generated `*.d.ts` file with specified formatter, eg. `prettier` | +| **[`eol`](#eol)** | `{String}` | Newline character to be used in generated `*.d.ts` files | +| **[`verifyOnly`](#verifyOnly)** | `{Boolean}` | Validate generated `*.d.ts` files and fail if an update is needed (useful in CI) | +| **[`disableLocalsExport`](#disableLocalsExport)** | `{Boolean}` | Disable the use of locals export. | +| **[`prettierConfigFile`](#prettierConfigFile)** | `{String}` | Path to prettier config file | ### `banner` @@ -188,6 +189,35 @@ module.exports = { }; ``` +### `prettierConfigFile` + +Path to the prettier config file + +```js +module.exports = { + module: { + rules: [ + { + test: /\.css$/i, + use: [ + { + loader: "@teamsupercell/typings-for-css-modules-loader", + options: { + prettierConfigFile: resolve(__dirname, '../.prettierrc'), + } + }, + { + loader: "css-loader", + options: { modules: true } + } + ] + } + ] + } +}; +``` + + ## Example diff --git a/src/index.js b/src/index.js index 19febfb..04b6b99 100644 --- a/src/index.js +++ b/src/index.js @@ -36,6 +36,11 @@ const schema = { "Validate generated `*.d.ts` files and fail if an update is needed (useful in CI). Defaults to `false`", type: "boolean", }, + prettierConfigFile: { + description: + "Path to prettier config file", + type: "string", + } }, additionalProperties: false, }; @@ -114,7 +119,7 @@ async function applyFormattingAndOptions(cssModuleDefinition, options) { options.formatter === "prettier" || (!options.formatter && canUsePrettier()) ) { - cssModuleDefinition = await applyPrettier(cssModuleDefinition); + cssModuleDefinition = await applyPrettier(cssModuleDefinition, options); } else { // at very least let's ensure we're using OS eol if it's not provided cssModuleDefinition = cssModuleDefinition.replace( @@ -128,12 +133,14 @@ async function applyFormattingAndOptions(cssModuleDefinition, options) { /** * @param {string} input + * @param {any} options * @returns {Promise} */ -async function applyPrettier(input) { +async function applyPrettier(input, options) { const prettier = require("prettier"); - const config = await prettier.resolveConfig("./", { + const configPath = options.prettierConfigFile ? options.prettierConfigFile : "./"; + const config = await prettier.resolveConfig(configPath, { editorconfig: true, });