Skip to content

Commit 86a7fda

Browse files
committed
fix: support tailwind.config.{ts,js,cjs,mjs} as fallback
1 parent 37c5694 commit 86a7fda

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ declare module 'twind' {
7575
}
7676
```
7777

78+
> If no `twind.config.{ts,js,cjs,mjs}` and a `tailwind.config.{ts,js,cjs,mjs}` exists, the compatible values from the tailwind config will be used.
79+
7880
### With VS Code
7981

8082
Currently you must manually install the plugin along side TypeScript in your workspace.

src/load-twind-config.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,29 @@ import locatePath from 'locate-path'
77

88
import type { Configuration } from 'twind'
99

10-
const CONFIG_FILES = ['twind.config.ts', 'twind.config.mjs', 'twind.config.js', 'twind.config.cjs']
10+
const TWIND_CONFIG_FILES = [
11+
'twind.config.ts',
12+
'twind.config.mjs',
13+
'twind.config.js',
14+
'twind.config.cjs',
15+
]
1116

17+
const TAILWIND_CONFIG_FILES = [
18+
'tailwind.config.ts',
19+
'tailwind.config.mjs',
20+
'tailwind.config.js',
21+
'tailwind.config.cjs',
22+
]
23+
24+
// TODO use typescript to check files
25+
// this.typescript.server.toNormalizedPath(fileName)
26+
// info.project.containsFile()
1227
export const findConfig = (cwd = process.cwd()): string | undefined =>
13-
locatePath.sync(CONFIG_FILES.map((file) => Path.resolve(cwd, 'config', file))) ||
14-
locatePath.sync(CONFIG_FILES.map((file) => Path.resolve(cwd, 'src', file))) ||
15-
locatePath.sync(CONFIG_FILES.map((file) => Path.resolve(cwd, 'public', file))) ||
16-
findUp.sync(CONFIG_FILES, { cwd })
28+
locatePath.sync(TWIND_CONFIG_FILES.map((file) => Path.resolve(cwd, 'config', file))) ||
29+
locatePath.sync(TWIND_CONFIG_FILES.map((file) => Path.resolve(cwd, 'src', file))) ||
30+
locatePath.sync(TWIND_CONFIG_FILES.map((file) => Path.resolve(cwd, 'public', file))) ||
31+
findUp.sync(TWIND_CONFIG_FILES, { cwd }) ||
32+
findUp.sync(TAILWIND_CONFIG_FILES, { cwd })
1733

1834
export const loadConfig = (configFile: string, cwd = process.cwd()): Configuration => {
1935
const result = buildSync({

0 commit comments

Comments
 (0)