Skip to content

Commit 671574f

Browse files
committed
Added configFile option
1 parent 7a2b2e1 commit 671574f

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
description:
3737
"Validate generated `*.d.ts` files and fail if an update is needed (useful in CI). Defaults to `false`",
3838
type: "boolean"
39+
},
40+
configFile: {
41+
description:
42+
"Path to prettier config file",
43+
type: "string"
3944
}
4045
},
4146
additionalProperties: false
@@ -112,7 +117,7 @@ async function applyFormattingAndOptions(cssModuleDefinition, options) {
112117
options.formatter === "prettier" ||
113118
(!options.formatter && canUsePrettier())
114119
) {
115-
cssModuleDefinition = await applyPrettier(cssModuleDefinition);
120+
cssModuleDefinition = await applyPrettier(cssModuleDefinition, options);
116121
} else {
117122
// at very least let's ensure we're using OS eol if it's not provided
118123
cssModuleDefinition = cssModuleDefinition.replace(
@@ -126,12 +131,14 @@ async function applyFormattingAndOptions(cssModuleDefinition, options) {
126131

127132
/**
128133
* @param {string} input
134+
* @param {any} options
129135
* @returns {Promise<string>}
130136
*/
131-
async function applyPrettier(input) {
137+
async function applyPrettier(input, options) {
132138
const prettier = require("prettier");
133139

134-
const config = await prettier.resolveConfig("./", {
140+
const configPath = options.configFile ? options.configFile : "./";
141+
const config = await prettier.resolveConfig(configPath, {
135142
editorconfig: true
136143
});
137144

0 commit comments

Comments
 (0)