Skip to content

Commit 29c5084

Browse files
committed
Added configFile option
1 parent 0747489 commit 29c5084

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

README.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ module.exports = {
3838

3939
## Options
4040

41-
| Name | Type | Description |
42-
| :-------------------------------------: | :---------: | :------------------------------------------------------------------------------: |
43-
| **[`banner`](#banner)** | `{String}` | To add a 'banner' prefix to each generated `*.d.ts` file |
44-
| **[`formatter`](#formatter)** | `{String}` | Formats the generated `*.d.ts` file with specified formatter, eg. `prettier` |
45-
| **[`eol`](#eol)** | `{String}` | Newline character to be used in generated `*.d.ts` files |
46-
| **[`verifyOnly`](#verifyOnly)** | `{Boolean}` | Validate generated `*.d.ts` files and fail if an update is needed (useful in CI) |
47-
| **[`disableLocalsExport`](#disableLocalsExport)** | `{Boolean}` | Disable the use of locals export. |
41+
| Name | Type | Description |
42+
| :-----------------------------------------------: | :---------: | :----------------------------------------------------------: |
43+
| **[`banner`](#banner)** | `{String}` | To add a 'banner' prefix to each generated `*.d.ts` file |
44+
| **[`formatter`](#formatter)** | `{String}` | Formats the generated `*.d.ts` file with specified formatter, eg. `prettier` |
45+
| **[`eol`](#eol)** | `{String}` | Newline character to be used in generated `*.d.ts` files |
46+
| **[`verifyOnly`](#verifyOnly)** | `{Boolean}` | Validate generated `*.d.ts` files and fail if an update is needed (useful in CI) |
47+
| **[`disableLocalsExport`](#disableLocalsExport)** | `{Boolean}` | Disable the use of locals export. |
48+
| **[`configFile`](#configFile)** | `{String}` | Path to prettier config file |
4849

4950
### `banner`
5051

@@ -188,6 +189,35 @@ module.exports = {
188189
};
189190
```
190191

192+
### `configFile`
193+
194+
Path to the prettier config file
195+
196+
```js
197+
module.exports = {
198+
module: {
199+
rules: [
200+
{
201+
test: /\.css$/i,
202+
use: [
203+
{
204+
loader: "@teamsupercell/typings-for-css-modules-loader",
205+
options: {
206+
configFile: resolve(__dirname, '../.prettierrc'),
207+
}
208+
},
209+
{
210+
loader: "css-loader",
211+
options: { modules: true }
212+
}
213+
]
214+
}
215+
]
216+
}
217+
};
218+
```
219+
220+
191221

192222
## Example
193223

src/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ const schema = {
3636
"Validate generated `*.d.ts` files and fail if an update is needed (useful in CI). Defaults to `false`",
3737
type: "boolean",
3838
},
39+
configFile: {
40+
description:
41+
"Path to prettier config file",
42+
type: "string",
43+
}
3944
},
4045
additionalProperties: false,
4146
};
@@ -114,7 +119,7 @@ async function applyFormattingAndOptions(cssModuleDefinition, options) {
114119
options.formatter === "prettier" ||
115120
(!options.formatter && canUsePrettier())
116121
) {
117-
cssModuleDefinition = await applyPrettier(cssModuleDefinition);
122+
cssModuleDefinition = await applyPrettier(cssModuleDefinition, options);
118123
} else {
119124
// at very least let's ensure we're using OS eol if it's not provided
120125
cssModuleDefinition = cssModuleDefinition.replace(
@@ -128,12 +133,14 @@ async function applyFormattingAndOptions(cssModuleDefinition, options) {
128133

129134
/**
130135
* @param {string} input
136+
* @param {any} options
131137
* @returns {Promise<string>}
132138
*/
133-
async function applyPrettier(input) {
139+
async function applyPrettier(input, options) {
134140
const prettier = require("prettier");
135141

136-
const config = await prettier.resolveConfig("./", {
142+
const configPath = options.configFile ? options.configFile : "./";
143+
const config = await prettier.resolveConfig(configPath, {
137144
editorconfig: true,
138145
});
139146

0 commit comments

Comments
 (0)