Skip to content

Commit

Permalink
fix: support tailwind.config.{ts,js,cjs,mjs} as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
sastan committed Mar 18, 2021
1 parent 37c5694 commit 86a7fda
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ declare module 'twind' {
}
```

> 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.
### With VS Code

Currently you must manually install the plugin along side TypeScript in your workspace.
Expand Down
26 changes: 21 additions & 5 deletions src/load-twind-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@ import locatePath from 'locate-path'

import type { Configuration } from 'twind'

const CONFIG_FILES = ['twind.config.ts', 'twind.config.mjs', 'twind.config.js', 'twind.config.cjs']
const TWIND_CONFIG_FILES = [
'twind.config.ts',
'twind.config.mjs',
'twind.config.js',
'twind.config.cjs',
]

const TAILWIND_CONFIG_FILES = [
'tailwind.config.ts',
'tailwind.config.mjs',
'tailwind.config.js',
'tailwind.config.cjs',
]

// TODO use typescript to check files
// this.typescript.server.toNormalizedPath(fileName)
// info.project.containsFile()
export const findConfig = (cwd = process.cwd()): string | undefined =>
locatePath.sync(CONFIG_FILES.map((file) => Path.resolve(cwd, 'config', file))) ||
locatePath.sync(CONFIG_FILES.map((file) => Path.resolve(cwd, 'src', file))) ||
locatePath.sync(CONFIG_FILES.map((file) => Path.resolve(cwd, 'public', file))) ||
findUp.sync(CONFIG_FILES, { cwd })
locatePath.sync(TWIND_CONFIG_FILES.map((file) => Path.resolve(cwd, 'config', file))) ||
locatePath.sync(TWIND_CONFIG_FILES.map((file) => Path.resolve(cwd, 'src', file))) ||
locatePath.sync(TWIND_CONFIG_FILES.map((file) => Path.resolve(cwd, 'public', file))) ||
findUp.sync(TWIND_CONFIG_FILES, { cwd }) ||
findUp.sync(TAILWIND_CONFIG_FILES, { cwd })

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

0 comments on commit 86a7fda

Please sign in to comment.