Support tailwind.config.ts (#1247)

Fixes #659
Fixes #633

Create Next App is using `tailwind.config.ts` in the TypeScript template. Since this is a very common use case it would be nice to preserve the type safety of the file.

I added new templates for TypeScript files. I see there is an issue #1073 which asks for ESM support as well. This is not included in this PR.

I also fixed the type error in the keyframes that is also handled in #636
This commit is contained in:
Luka Hartwig
2023-10-19 19:44:11 +02:00
committed by GitHub
parent 9091dcdc1b
commit 4ec8a67dab
9 changed files with 159 additions and 21 deletions

View File

@@ -228,12 +228,25 @@ export async function runInit(cwd: string, config: Config) {
const extension = config.tsx ? "ts" : "js"
const tailwindConfigExtension = path.extname(
config.resolvedPaths.tailwindConfig
)
let tailwindConfigTemplate: string
if (tailwindConfigExtension === ".ts") {
tailwindConfigTemplate = config.tailwind.cssVariables
? templates.TAILWIND_CONFIG_TS_WITH_VARIABLES
: templates.TAILWIND_CONFIG_TS
} else {
tailwindConfigTemplate = config.tailwind.cssVariables
? templates.TAILWIND_CONFIG_WITH_VARIABLES
: templates.TAILWIND_CONFIG
}
// Write tailwind config.
await fs.writeFile(
config.resolvedPaths.tailwindConfig,
config.tailwind.cssVariables
? template(templates.TAILWIND_CONFIG_WITH_VARIABLES)({ extension })
: template(templates.TAILWIND_CONFIG)({ extension }),
template(tailwindConfigTemplate)({ extension }),
"utf8"
)