Skip to content

配置

配置和定制您的Tailwind安装指南。

因为 Tailwind 是一个用于构建定制用户界面的框架,它从头开始就考虑了定制化。

默认情况下,Tailwind 会在项目根目录中寻找一个可选的 tailwind.config.js 文件,您可以在其中定义任何自定义内容。

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ['./src/**/*.{html,js}'],
  theme: {
    colors: {
      'blue': '#1fb6ff',
      'purple': '#7e5bef',
      'pink': '#ff49db',
      'orange': '#ff7849',
      'green': '#13ce66',
      'yellow': '#ffc82c',
      'gray-dark': '#273444',
      'gray': '#8492a6',
      'gray-light': '#d3dce6',
    },
    fontFamily: {
      sans: ['Graphik', 'sans-serif'],
      serif: ['Merriweather', 'serif'],
    },
    extend: {
      spacing: {
        '8xl': '96rem',
        '9xl': '128rem',
      },
      borderRadius: {
        '4xl': '2rem',
      }
    }
  },
}

配置文件的每个部分都是可选的,所以您只需要指定您想要更改的部分。任何缺失的部分都将回退到 Tailwind 的默认配置

创建您的配置文件

使用安装 tailwindcss npm 包时包含的 Tailwind CLI 实用程序为您的项目生成 Tailwind 配置文件:

shell
npx tailwindcss init

这将在您的项目根目录创建一个最小的 tailwind.config.js 文件:

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
}

使用不同的文件名

若要使用除 tailwind.config.js 之外的名称,请将其作为命令行参数传递:

shell
npx tailwindcss init tailwindcss-config.js

当您使用自定义文件名时,您需要在使用 Tailwind CLI 工具编译 CSS 时将其指定为命令行参数:

shell
npx tailwindcss -c ./tailwindcss-config.js -i input.css -o output.css

如果您正在使用 Tailwind 作为 PostCSS 插件,您需要在 PostCSS 配置中指定您的自定义配置路径:

js
module.exports = {
  plugins: {
    tailwindcss: { config: './tailwindcss-config.js' },
  },
}

或者,您可以使用 @config 指令来指定自定义配置路径:

css
@config "./tailwindcss-config.js";

@tailwind base;
@tailwind components;
@tailwind utilities;

函数和指令文档中了解更多关于 @config 指令的信息。

使用 ESM 或 TypeScript

您还可以在 ESM 或甚至 TypeScript 中配置 Tailwind CSS:

js
/** @type {import('tailwindcss').Config} */
export default {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
}
typescript
import type { Config } from 'tailwindcss'

export default {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
} satisfies Config

当您运行 npx tailwindcss init 时,我们将检测您的项目是否为 ES 模块,并自动生成具有正确语法的配置文件。

您还可以使用 --esm 标志显式生成一个ESM配置文件:

sh
npx tailwindcss init --esm

生成 TypeScript 配置文件,请使用 --ts 标志:

sh
npx tailwindcss init --ts

生成一个 PostCSS 配置文件

如果您想同时生成一个基本的 postcss.config.js 文件和您的 tailwind.config.js 文件,可以使用 -p 标志

shell
npx tailwindcss init -p

这将在您的项目中生成一个 postcss.config.js 文件,看起来像这样:

js
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

搭建整个默认配置

对于大多数用户,我们鼓励您尽可能保持配置文件的最小化,并只指定您想要自定义的内容。

如果您更喜欢生成一个包含 Tailwind 的所有默认配置的完整配置文件,请使用 --full 选项:

shell
npx tailwindcss init --full

您将获得一个与 Tailwind 内部使用的默认配置文件相匹配的文件。

配置选项

内容

content 部分是您配置所有 HTML 模板、JS 组件以及包含 Tailwind 类名的其他文件路径的地方。

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './pages/**/*.{html,js}',
    './components/**/*.{html,js}',
  ],
  // ...
}

内容配置文档中了解更多关于配置您的内容来源的信息。

主题

theme 部分是您定义颜色调色板、字体、字体比例、边框大小、断点等与网站视觉设计相关的内容。

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  // ...
  theme: {
    colors: {
      'blue': '#1fb6ff',
      'purple': '#7e5bef',
      'pink': '#ff49db',
      'orange': '#ff7849',
      'green': '#13ce66',
      'yellow': '#ffc82c',
      'gray-dark': '#273444',
      'gray': '#8492a6',
      'gray-light': '#d3dce6',
    },
    fontFamily: {
      sans: ['Graphik', 'sans-serif'],
      serif: ['Merriweather', 'serif'],
    },
    extend: {
      spacing: {
        '8xl': '96rem',
        '9xl': '128rem',
      },
      borderRadius: {
        '4xl': '2rem',
      }
    }
  }
}

主题配置指南中了解更多关于默认主题以及如何自定义它的信息。

插件

plugins 部分允许您向 Tailwind 注册插件,这些插件可用于生成额外的实用程序、组件、基本样式或自定义变体。

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  // ...
  plugins: [
    require('@tailwindcss/forms'),
    require('@tailwindcss/aspect-ratio'),
    require('@tailwindcss/typography'),
    require('tailwindcss-children'),
  ],
}

插件作者指南中了解更多关于编写自己的插件的信息。

预设

presets 部分允许您指定自定义基本配置,而不是使用 Tailwind 的默认基本配置。

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  // ...
  presets: [
    require('@acmecorp/base-tailwind-config')
  ],

  // Project-specific customizations
  theme: {
    //...
  },
}

预设文档中了解更多关于预设的信息。

前缀

选项 prefix 允许您向 Tailwind 生成的所有实用程序类添加自定义前缀。当在现有 CSS 的基础上叠加 Tailwind 时,可能会出现命名冲突,这时这个功能就非常有用。

例如,您可以通过设置 prefix 选项来添加 tw- 前缀。

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  prefix: 'tw-',
}

现在每个类都将使用配置的前缀生成:

css
.tw-text-left {
  text-align: left;
}
.tw-text-center {
  text-align: center;
}
.tw-text-right {
  text-align: right;
}
/* etc. */

重要的是要理解,这个前缀是在任何变体修饰符之后添加的。这意味着具有响应或状态修饰符的类,如 sm:hover: ,仍然会先出现响应或状态修饰符,然后是您自定义的前缀出现在冒号后面:

html
<div class="tw-text-lg md:tw-text-xl tw-bg-red-500 hover:tw-bg-blue-500">
  <!-- -->
</div>

负值的破折号修饰符应该添加在前缀之前,所以如果您已将 tw- 配置为前缀,则 -mt-8 将变为 -tw-mt-8

html
<div class="-tw-mt-8">
  <!-- -->
</div>

前缀仅添加到由Tailwind生成的类;不会向您自定义的类添加前缀。

这意味着如果您添加自己的自定义实用程序,就像这样:

css
@layer utilities {
  .bg-brand-gradient { /* ... */ }
}

...生成的变体不会带有您配置的前缀:

css
.bg-brand-gradient { /* ... */ }
.hover\:bg-brand-gradient:hover { /* ... */ }

如果您想要为自己的实用程序添加前缀,只需将前缀添加到类定义中:

css
@layer utilities {
  .tw-bg-brand-gradient { /* ... */ }
}

重要

选项允许您控制是否应该使用 !important 标记 Tailwind 的实用程序。当与具有高特异性选择器的现有 CSS 一起使用 Tailwind 时,这可能非常有用。

要将实用程序生成为 !important ,请将配置选项中的 important 键设置为 true

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  important: true,
}

现在所有Tailwind的实用类将生成为 !important

css
.leading-none {
  line-height: 1 !important;
}
.leading-tight {
  line-height: 1.25 !important;
}
.leading-snug {
  line-height: 1.375 !important;
}
/* etc. */

这也适用于您在 CSS 中使用 @layer utilities 指令定义的任何自定义实用程序:

css
/* Input */
@layer utilities {
  .bg-brand-gradient {
    background-image: linear-gradient(#3490dc, #6574cd);
  }
}

/* Output */
.bg-brand-gradient {
  background-image: linear-gradient(#3490dc, #6574cd) !important;
}

选择器策略

important 设置为 true 可能会在合并第三方 JS 库时引入一些问题,这些库会向您的元素添加内联样式。在这种情况下,Tailwind 的 !important 实用程序会覆盖内联样式,这可能会破坏您预期的设计。

为了解决这个问题,您可以将 important 设置为 ID 选择器,如 #app

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  // ...
  important: '#app',
}

此配置将使用给定的选择器为所有实用程序添加前缀,从而有效地增加它们的特异性,而不实际使它们 !important

在指定 important 选择器之后,您需要确保站点的根元素与其匹配。使用上面的示例,我们需要将站点的根元素的 id 属性设置为 app ,以便样式能够正常工作。

在您的配置全部设置好并且根元素与您的 Tailwind 配置中的选择器匹配之后,Tailwind 的所有工具类将具有足够高的特异性,可以击败项目中使用的其他类,而不会干扰内联样式。

html
<html>
<!-- ... -->
<style>
  .high-specificity .nested .selector {
    color: blue;
  }
</style>
<body id="app">
  <div class="high-specificity">
    <div class="nested">
      <!-- Will be red-500 -->
      <div class="selector text-red-500"><!-- ... --></div>
    </div>
  </div>

  <!-- Will be #bada55 -->
  <div class="text-red-500" style="color: #bada55;"><!-- ... --></div>
</body>
</html>

在使用选择器策略时,请确保包含根选择器的模板文件已包含在内容配置中,否则在生产环境构建时将会移除所有的 CSS。

重要的修饰符

或者,您可以通过在开头添加一个 ! 字符来使任何实用程序变得重要:

html
<p class="!font-medium font-bold">
  This will be medium even though bold comes later in the CSS.
</p>

! 始终位于实用程序名称的开头,位于任何变体之后,但位于任何前缀之前:

html
<div class="sm:hover:!tw-font-bold">

在罕见情况下,当您需要增加特异性时,这可能是有用的,因为您正在与一些您无法控制的样式作斗争。

分隔符

separator 选项允许您自定义用于将修饰符(屏幕尺寸, hoverfocus 等)与实用程序名称( text-centeritems-end 等)分隔的字符。

我们默认使用冒号( : ),但如果您使用像 Pug 这样不支持类名中的特殊字符的模板语言,更改这一点可能会很有用。

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  separator: '_',
}

核心插件

corePlugins 部分允许您完全禁用 Tailwind 在您的项目中不需要的默认生成的类。

要禁用特定的核心插件,请为 corePlugins 提供一个对象,将这些插件设置为 false

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  corePlugins: {
    float: false,
    objectFit: false,
    objectPosition: false,
  }
}

如果您想要将应启用的核心插件列入白名单,请提供一个包含您想要使用的核心插件列表的数组:

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  corePlugins: [
    'margin',
    'padding',
    'backgroundColor',
    // ...
  ]
}

如果您想禁用Tailwind的所有核心插件,并仅将Tailwind作为处理自定义插件的工具,请提供一个空数组:

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  corePlugins: []
}

这是每个核心插件的参考列表:

Core PluginDescription
accentColoraccent-color 这样的实用工具 accent-green-800
accessibilitysr-onlynot-sr-only 这样的实用工具
alignContentalign-content 这样的实用工具 content-between
alignItemsalign-items 这样的实用工具 items-center
alignSelfalign-self 这样的实用工具 self-end
animationanimation 这样的实用工具 animate-ping
appearanceappearance 这样的实用工具 appearance-none
aspectRatioaspect-ratio 这样的实用工具 aspect-square
backdropBlurbackdrop-blur 这样的实用工具 backdrop-blur-md
backdropBrightnessbackdrop-brightness 这样的实用工具 backdrop-brightness-100
backdropContrastbackdrop-contrast 这样的实用工具 backdrop-contrast-100
backdropFilterbackdrop-filter 这样的实用工具,比如 backdrop-filter
backdropGrayscalebackdrop-grayscale 这样的实用工具 backdrop-grayscale-0
backdropHueRotatebackdrop-hue-rotate 这样的实用工具 backdrop-hue-rotate-30
backdropInvertbackdrop-invert 这样的实用工具 backdrop-invert-0
backdropOpacitybackdrop-opacity 这样的实用工具 backdrop-opacity-50
backdropSaturatebackdrop-saturate 这样的实用工具 backdrop-saturate-100
backdropSepiabackdrop-sepia 这样的实用工具 backdrop-sepia-0
backgroundAttachmentbackground-attachment 这样的实用工具 bg-local
backgroundBlendModebackground-blend-mode 这样的实用工具 bg-blend-color-burn
backgroundClipbackground-clip 这样的实用工具 bg-clip-padding
backgroundColorbackground-color 这样的实用工具 bg-green-800
backgroundImagebackground-image 这样的实用工具 bg-gradient-to-br
backgroundOpacitybackground-color 不透明度实用程序,如 bg-opacity-25
backgroundOriginbackground-origin 这样的实用工具 bg-origin-padding
backgroundPositionbackground-position 这样的实用工具 bg-left-top
backgroundRepeatbackground-repeat 这样的实用工具 bg-repeat-x
backgroundSizebackground-size 这样的实用工具 bg-cover
blurblur 这样的实用工具 blur-md
borderCollapseborder-collapse 这样的实用工具 border-collapse
borderColorborder-color 这样的实用工具 border-e-green-800
borderOpacityborder-color 不透明度实用程序,如 border-opacity-25
borderRadiusborder-radius 这样的实用工具 rounded-ss-lg
borderSpacingborder-spacing 这样的实用工具 border-spacing-x-28
borderStyleborder-style 这样的实用工具 border-dotted
borderWidthborder-width 这样的实用工具 border-e-4
boxDecorationBreakbox-decoration-break 这样的实用工具 decoration-clone
boxShadowbox-shadow 这样的实用工具 shadow-lg
boxShadowColorbox-shadow-color 这样的实用工具 shadow-green-800
boxSizingbox-sizing 这样的实用工具 box-border
breakAfterbreak-after 这样的实用工具 break-after-avoid-page
breakBeforebreak-before 这样的实用工具 break-before-avoid-page
breakInsidebreak-inside 这样的实用工具 break-inside-avoid
brightnessbrightness 这样的实用工具 brightness-100
captionSidecaption-side 这样的实用工具 caption-top
caretColorcaret-color 这样的实用工具 caret-green-800
clearclear 这样的实用工具 clear-left
columnscolumns 这样的实用工具 columns-auto
container组件 container
contentcontent 这样的实用工具 content-none
contrastcontrast 这样的实用工具 contrast-100
cursorcursor 这样的实用工具 cursor-grab
displaydisplay 这样的实用工具 table-column-group
divideColor元素之间的 border-color 实用程序,如 divide-slate-500
divideOpacitydivide-opacity 这样的实用工具 divide-opacity-50
divideStyledivide-style 这样的实用工具 divide-dotted
divideWidth元素之间的 border-width 实用程序,如 divide-x-2
dropShadowdrop-shadow 这样的实用工具 drop-shadow-lg
fillfill 这样的实用工具 fill-green-700
filterfilter 这样的实用工具 filter
flexflex 这样的实用工具 flex-auto
flexBasisflex-basis 这样的实用工具 basis-px
flexDirectionflex-direction 这样的实用工具 flex-row-reverse
flexGrowflex-grow 这样的实用工具 flex-grow
flexShrinkflex-shrink 这样的实用工具 flex-shrink
flexWrapflex-wrap 这样的实用工具 flex-wrap-reverse
floatfloat 这样的实用工具 float-right
fontFamilyfont-family 这样的实用工具 font-serif
fontSizefont-size 这样的实用工具 text-3xl
fontSmoothingfont-smoothing 这样的实用工具 antialiased
fontStylefont-style 这样的实用工具 italic
fontVariantNumericfont-variant-numeric 这样的实用工具 oldstyle-nums
fontWeightfont-weight 这样的实用工具 font-medium
forcedColorAdjustforced-color-adjust 这样的实用工具 forced-color-adjust-auto
gapgap 这样的实用工具 gap-x-28
gradientColorStopsgradient-color-stops 这样的实用工具 via-emerald-700
grayscalegrayscale 这样的实用工具 grayscale-0
gridAutoColumnsgrid-auto-columns 这样的实用工具 auto-cols-min
gridAutoFlowgrid-auto-flow 这样的实用工具 grid-flow-dense
gridAutoRowsgrid-auto-rows 这样的实用工具 auto-rows-min
gridColumngrid-column 这样的实用工具 col-span-6
gridColumnEndgrid-column-end 这样的实用工具 col-end-7
gridColumnStartgrid-column-start 这样的实用工具 col-start-7
gridRowgrid-row 这样的实用工具 row-span-6
gridRowEndgrid-row-end 这样的实用工具 row-end-7
gridRowStartgrid-row-start 这样的实用工具 row-start-7
gridTemplateColumnsgrid-template-columns 这样的实用工具 grid-cols-7
gridTemplateRowsgrid-template-rows 这样的实用工具 grid-rows-7
heightheight 这样的实用工具 h-96
hueRotatehue-rotate 这样的实用工具 hue-rotate-30
hyphenshyphens 这样的实用工具 hyphens-manual
insetinset 这样的实用工具 end-44
invertinvert 这样的实用工具 invert-0
isolationisolation 这样的实用工具 isolate
justifyContentjustify-content 这样的实用工具 justify-center
justifyItemsjustify-items 这样的实用工具 justify-items-end
justifySelfjustify-self 这样的实用工具 justify-self-end
letterSpacingletter-spacing 这样的实用工具 tracking-normal
lineClampline-clamp 这样的实用工具 line-clamp-4
lineHeightline-height 这样的实用工具 leading-9
listStyleImagelist-style-image 这样的实用工具 list-image-none
listStylePositionlist-style-position 这样的实用工具 list-inside
listStyleTypelist-style-type 这样的实用工具 list-disc
marginmargin 这样的实用工具 me-28
maxHeightmax-height 这样的实用工具 max-h-44
maxWidthmax-width 这样的实用工具 max-w-80
minHeightmin-height 这样的实用工具 min-h-44
minWidthmin-width 这样的实用工具 min-w-36
mixBlendModemix-blend-mode 这样的实用工具 mix-blend-hard-light
objectFitobject-fit 这样的实用工具 object-fill
objectPositionobject-position 这样的实用工具 object-left-top
opacityopacity 这样的实用工具 opacity-50
orderorder 这样的实用工具 order-8
outlineColoroutline-color 这样的实用工具 outline-green-800
outlineOffsetoutline-offset 这样的实用工具 outline-offset-2
outlineStyleoutline-style 这样的实用工具 outline-dashed
outlineWidthoutline-width 这样的实用工具 outline-2
overflowoverflow 这样的实用工具 overflow-x-hidden
overscrollBehavioroverscroll-behavior 这样的实用工具 overscroll-y-contain
paddingpadding 这样的实用工具 pe-28
placeContentplace-content 这样的实用工具 place-content-between
placeItemsplace-items 这样的实用工具 place-items-center
placeSelfplace-self 这样的实用工具 place-self-end
placeholderColorplaceholder-color 这样的占位符实用程序 placeholder-red-600
placeholderOpacityplaceholder-opacity-25 这样的占位符不透明度实用程序
pointerEventspointer-events 这样的实用工具 pointer-events-none
positionposition 这样的实用工具 absolute
preflightTailwind 的基础/重置样式
resizeresize 这样的实用工具 resize-y
ringColorring-color 这样的实用工具 ring-green-800
ringOffsetColorring-offset-color 这样的实用工具 ring-offset-green-800
ringOffsetWidthring-offset-width 这样的实用工具 ring-offset-2
ringOpacityring-opacity 这样的实用工具 ring-opacity-50
ringWidthring-width 这样的实用工具 ring-4
rotaterotate 这样的实用工具 rotate-6
saturatesaturate 这样的实用工具 saturate-100
scalescale 这样的实用工具 scale-x-95
scrollBehaviorscroll-behavior 这样的实用工具 scroll-auto
scrollMarginscroll-margin 这样的实用工具 scroll-me-28
scrollPaddingscroll-padding 这样的实用工具 scroll-pe-28
scrollSnapAlignscroll-snap-align 这样的实用工具 snap-end
scrollSnapStopscroll-snap-stop 这样的实用工具 snap-normal
scrollSnapTypescroll-snap-type 这样的实用工具 snap-y
sepiasepia 这样的实用工具 sepia-0
sizesize 这样的实用工具 size-0.5
skewskew 这样的实用工具 skew-x-12
spacespace-between 实用程序,如 space-x-4
strokestroke 这样的实用工具 stroke-green-700
strokeWidthstroke-width 这样的实用工具 stroke-1
tableLayouttable-layout 这样的实用工具 table-auto
textAligntext-align 这样的实用工具 text-right
textColortext-color 这样的实用工具 text-green-800
textDecorationtext-decoration 这样的实用工具 overline
textDecorationColortext-decoration-color 这样的实用工具 decoration-green-800
textDecorationStyletext-decoration-style 这样的实用工具 decoration-dotted
textDecorationThicknesstext-decoration-thickness 这样的实用工具 decoration-4
textIndenttext-indent 这样的实用工具 indent-28
textOpacitytext-opacity 这样的实用工具 text-opacity-50
textOverflowtext-overflow 这样的实用工具 overflow-ellipsis
textTransformtext-transform 这样的实用工具 lowercase
textUnderlineOffsettext-underline-offset 这样的实用工具 underline-offset-2
textWraptext-wrap 这样的实用工具 text-nowrap
touchActiontouch-action 这样的实用工具 touch-pan-right
transformtransform 实用程序(用于启用变换功能)
transformOrigintransform-origin 这样的实用工具 origin-bottom-right
transitionDelaytransition-delay 这样的实用工具 delay-200
transitionDurationtransition-duration 这样的实用工具 duration-200
transitionPropertytransition-property 这样的实用工具 transition-colors
transitionTimingFunctiontransition-timing-function 这样的实用工具 ease-in
translatetranslate 这样的实用工具 translate-x-full
userSelectuser-select 这样的实用工具 select-text
verticalAlignvertical-align 这样的实用工具 align-bottom
visibilityvisibility 这样的实用工具 invisible
whitespacewhitespace 这样的实用工具 whitespace-pre
widthwidth 这样的实用工具 w-2.5
willChangewill-change 这样的实用工具 will-change-scroll
wordBreakword-break 这样的实用工具 break-words
zIndexz-index 这样的实用工具 z-30

使用多个配置

对于需要使用不同的 Tailwind 配置生成多个 CSS 文件的项目,请使用 @config 指令来指定每个 CSS 入口点应该使用哪个配置文件:

css
@config "./tailwind.site.config.js";

@tailwind base;
@tailwind components;
@tailwind utilities;
css
@config "./tailwind.admin.config.js";

@tailwind base;
@tailwind components;
@tailwind utilities;

函数和指令文档中了解更多关于 @config 指令的信息。

JavaScript 中的引用

通常情况下,将配置值引用到自己的客户端 JavaScript 中是非常有用的 — 例如,在 React 或 Vue 组件中动态应用内联样式时,可以访问一些主题值。

为了简化这一过程,Tailwind 提供了一个 resolveConfig 助手,您可以使用它来生成完全合并的配置对象版本:

js
import resolveConfig from 'tailwindcss/resolveConfig'
import tailwindConfig from './tailwind.config.js'

const fullConfig = resolveConfig(tailwindConfig)

fullConfig.theme.width[4]
// => '1rem'

fullConfig.theme.screens.md
// => '768px'

fullConfig.theme.boxShadow['2xl']
// => '0 25px 50px -12px rgba(0, 0, 0, 0.25)'

请注意,这将在构建时传递地拉取很多我们的构建时依赖项,导致客户端包大小更大。为了避免这种情况,我们建议使用类似 babel-plugin-preval 这样的工具,在构建时生成您配置的静态版本。

TypeScript 类型

我们为 tailwind.config.js 文件提供了第一方 TypeScript 类型,这些类型为您提供了各种有用的 IDE 支持,并且使得在不太频繁地参考文档的情况下更容易对配置进行更改。

使用 Tailwind CLI 生成的配置文件默认包含必要的类型注释,但如果要手动配置 TypeScript 类型,只需在配置对象上方添加类型注释:

js
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    // ...
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

Released under the MIT License.