Skip to content

Commit

Permalink
Add support for tailwind config files in ESM/TS format
Browse files Browse the repository at this point in the history
Tailwind v3.3 added support for config files in ESM/TS format.
See https://tailwindcss.com/blog/tailwindcss-v3-3#esm-and-typescript-support
  • Loading branch information
albohlabs committed Apr 10, 2023
1 parent 59f9b3f commit 80e45fa
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 6 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -118,7 +118,6 @@
"eslint-plugin-unicorn": "^44.0.2",
"glob-all": "^3.3.0",
"husky": "4.3.8",
"import-fresh": "^3.3.0",
"jest": "^29.2.2",
"lint-staged": "^13.0.3",
"microbundle": "^0.15.1",
Expand Down
4 changes: 2 additions & 2 deletions src/core/lib/configHelpers.ts
@@ -1,7 +1,6 @@
import { resolve, dirname } from 'path'
import { existsSync } from 'fs'
import escalade from 'escalade/sync'
import requireFresh from 'import-fresh'
import { configTwinValidators, configDefaultsTwin } from './twinConfig'
import defaultTwinConfig from './defaultTailwindConfig'
import { resolveTailwindConfig, getAllConfigs } from './util/twImports'
Expand All @@ -15,6 +14,7 @@ import type {
Assert,
AssertContext,
} from 'core/types'
import loadConfig from 'tailwindcss/loadConfig'

type Validator = [(value: unknown) => boolean, string]

Expand Down Expand Up @@ -76,7 +76,7 @@ function getTailwindConfig({

const configs = [
// User config
...(configExists ? getAllConfigs(requireFresh(configPath as string)) : []),
...(configExists ? getAllConfigs(loadConfig(configPath as string)) : []),
// Default config
...getAllConfigs(defaultTwinConfig),
]
Expand Down
@@ -1,4 +1,6 @@
module.exports = {
import type { Config } from 'tailwindcss'

export default {
theme: {
animation: {
'zoom-.5': 'zoom-.5 2s',
Expand Down Expand Up @@ -50,4 +52,4 @@ module.exports = {
customFontWeightAsNumber: 800,
},
},
}
} satisfies Config
5 changes: 5 additions & 0 deletions tests/plugin.test.js
Expand Up @@ -30,6 +30,11 @@ pluginTester({
) && {
config: path.join(path.dirname(file), 'tailwind.config.js'),
}),
...(fs.existsSync(
path.join(path.dirname(file), 'tailwind.config.ts')
) && {
config: path.join(path.dirname(file), 'tailwind.config.ts'),
}),
...(fs.existsSync(configFile(file)) &&
JSON.parse(fs.readFileSync(configFile(file), 'utf8'))),
},
Expand Down
52 changes: 52 additions & 0 deletions types/tests/__fixtures__/config/tailwind.config.d.ts
@@ -0,0 +1,52 @@
declare const _default: {
theme: {
animation: {
'zoom-.5': string
}
colors: {
number: number
purple: string
'purple-hyphen': string
mycolors: {
DEFAULT: string
'a-purple': string
'a-number': number
}
'my-blue': {
100: string
}
'color-opacity': ({ opacityVariable }: { opacityVariable: any }) => string
color: {
deep: {
config: {
500: string
}
}
}
blue: {
DEFAULT: string
gray: {
200: string
}
}
'blue-gray': {
DEFAULT: string
200: string
}
'blue-gray-green': {
DEFAULT: string
200: string
'deep-dish': {
DEFAULT: string
200: string
}
}
'blue-gray-green-pink': string
}
fontWeight: {
customFontWeightAsString: string
customFontWeightAsNumber: number
}
}
}
export default _default

0 comments on commit 80e45fa

Please sign in to comment.