在 Vue 3 中安装 Tailwind CSS 时,是否需要 postcss.config.js 文件?

When installing Tailwind CSS in Vue 3, do I need a postcss.config.js file?

我正在努力在没有 Vite 的 Vue 3 项目中安装 Tailwind CSS 2.2.10(所以 "Install Tailwind CSS with Vue 3 and Vite说明不适用)

在安装文档中,“Add Tailwind as a PostCSS plugin”部分为:

Add tailwindcss and autoprefixer to your PostCSS configuration. Most of the time this is a postcss.config.js file at the root of your project, but it could also be a .postcssrc file, or postcss key in your package.json file.

我的 package.json 文件中的 "postcss": "^8.3.6", 是文档中提到的“postcss 密钥”(见上文粗体),还是我需要 postcss.config.js 文件?

谢谢!

不,package.json 文件中的 "postcss": "^8.3.6" 不是 文档中提到的“postcss 密钥”——它是 [= 的版本说明符12=]依赖。

“package.json 文件 中的 postcss 键”指的是 JSON 中的 postcss 根 属性:

// package.json
{
  "name": "my-project",
  "version": "0.1.0",
  "dependencies": {
    /*...*/
  }, 
  "postcss": {
    "plugins": {
      "tailwindcss": {},
      "autoprefixer": {},
    }
  }
}

如果您不想将配置存储在 package.json 中,您可以使用读取 PostCSS 配置的其他可能位置之一,包括 postcss.config.js。但是,您不需要多个 PostCSS 配置文件(例如 postcss.config.js 除了 package.json 中的 postcss 键)。