npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

tailwindcss-config

v1.1.3

Published

load tailwindcss config function

Downloads

15,050

Readme

tailwindcss-config

A lightweight utility for dynamically loading Tailwind CSS configuration files. It supports multiple formats and provides a seamless way to work with Tailwind configuration in your projects.


Features

  • Multi-format support: Handles .js, .cjs, .mjs, .ts, .cts, and .mts configuration files.
  • Automatic discovery: Searches for configuration files in the current working directory or a specified path.
  • Graceful fallback: Returns undefined if no configuration is found, ensuring compatibility with dynamic setups.
  • TypeScript support: Fully typed for use in TypeScript projects.

Installation

Install the package via npm:

npm i -D tailwindcss-config

Or using Yarn:

yarn add -D tailwindcss-config

Usage

Import the Function

import { loadConfig } from 'tailwindcss-config'

Examples

1. Default Usage

The function searches for Tailwind CSS configuration files in the current working directory:

(async () => {
  const config = await loadConfig()
  console.log(config)
})()

2. Specify a Configuration File

Explicitly specify a path to a Tailwind CSS configuration file:

(async () => {
  const config = await loadConfig({ config: './tailwind.config.ts' })
  console.log(config)
})()

3. Change the Working Directory

Set a custom working directory to search for Tailwind configuration files:

(async () => {
  const config = await loadConfig({ cwd: '/my/project/directory' })
  console.log(config)
})()

Supported Configuration Formats

The utility supports the following file types:

  • tailwind.config.js
  • tailwind.config.cjs
  • tailwind.config.mjs
  • tailwind.config.ts
  • tailwind.config.cts
  • tailwind.config.mts

Dynamic imports are powered by jiti, allowing the utility to handle various file types seamlessly.


API Reference

loadConfig(options?: Partial<LoadConfigOptions>)

Parameters

| Parameter | Type | Description | Default | | ---------------- | ---------------------------- | ----------------------------------------------- | --------------- | | options | Partial<LoadConfigOptions> | Options to customize configuration loading. | {} | | options.cwd | string | Directory to search for configuration files. | process.cwd() | | options.config | string | Path to a specific Tailwind configuration file. | undefined |

Returns

A Promise that resolves to a Config object or undefined if no configuration file is found.


File Search Order

The utility uses lilconfig to locate configuration files. It searches for the following files (in order):

  1. tailwind.config.js
  2. tailwind.config.cjs
  3. tailwind.config.mjs
  4. tailwind.config.ts
  5. tailwind.config.cts
  6. tailwind.config.mts

Example Project Structure

my-project/
├── src/
│   └── index.ts
├── tailwind.config.ts
└── tailwind.config.js

Loading Configuration

(async () => {
  const config = await loadConfig({ cwd: './my-project' })
  console.log(config)
})()

Error Handling

The loadConfig function does not throw an error if no configuration is found. Instead, it resolves to undefined. This ensures compatibility with projects where Tailwind configuration is optional or dynamically generated.


Contributing

Contributions are welcome! To get started:

  1. Fork this repository.
  2. Create a new branch for your feature or bug fix.
  3. Submit a pull request with a clear description of your changes.

License

This project is licensed under the MIT License.