Tailwind CSS 是用 JavaScript 编写的,并以 npm 包的形式分发,这意味着你必须始终安装 Node.js 和 npm 才能使用它。
🌐 Tailwind CSS is written in JavaScript and distributed as an npm package, which means you've always had to have Node.js and npm installed to use it.
这使得在使用 npm 并不常见的项目中集成变得更加困难,而且随着像 Rails 和 Phoenix 这样的工具默认逐渐抛弃 npm,我们需要找到一种方法,让人们在这些项目中使用 Tailwind,而不必强迫他们去采用一个完全独立的工具生态系统。
今天我们宣布推出一个新的 独立 CLI 构建版本,它可以让你在一个独立的可执行文件中充分使用 Tailwind CLI 的全部功能——无需 Node.js 或 npm。
开始(Get started)
要安装它,请从 GitHub 的 最新版本中获取适合你平台的可执行文件,并确保赋予其可执行权限:
# Example for macOS arm64curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64chmod +x tailwindcss-macos-arm64mv tailwindcss-macos-arm64 tailwindcss现在,你可以像使用我们的 npm 分布式 CLI 工具一样使用它:
🌐 Now you can use it just like our npm-distributed CLI tool:
# Create a tailwind.config.js file./tailwindcss init# Start a watcher./tailwindcss -i input.css -o output.css --watch# Compile and minify your CSS for production./tailwindcss -i input.css -o output.css --minify我们甚至打包了所有官方插件的最新版本,因此如果你想在项目中使用它们,只需像在基于 Node 的项目中那样在你的 tailwind.config.js 文件中 require 它们即可:
🌐 We've even bundled the latest versions of all of our first-party plugins, so if you want to use them in your project, just require them in your tailwind.config.js file like you would in a Node-based project:
module.exports = { // ... plugins: [require("@tailwindcss/forms"), require("@tailwindcss/typography")],};你可以通过一个方便、可移植的软件包获得我们标准 npm 分布式 CLI 的所有功能 - 无需任何依赖。
🌐 You get all the power of our standard npm-distributed CLI in a convenient, portable package — no dependencies required.
它是如何工作的?(How does it work?)
我们并没有用 Rust 重写 Tailwind 或类似的东西(还没有…)——我们实际上使用了 pkg,这是 Vercel 的一个非常酷的项目,它可以让你将 Node.js 项目打包成可执行文件,通过将项目所需的所有部分直接打包到可执行文件中,从而无需安装 Node.js 就能运行。
这使得你仍然能够使用 tailwind.config.js 文件并充分发挥 JavaScript 的能力,而不是像 JSON 这样的静态格式。
🌐 This is what makes it possible for you to still use a tailwind.config.js file with the full power of JavaScript, rather than a static format like JSON.
我应该使用哪个 CLI?(Which CLI should I use?)
如果你已经在项目中使用 npm,请使用我们一直提供的 npm 分发版 CLI。它更新更简单,文件体积更小,而且你本身就已经在这个生态系统中 — 使用独立版本完全没有任何好处。
🌐 If you are already using npm in your project, use the npm-distributed version of our CLI that we've always provided. It's simpler to update, the file size is smaller, and you're already in the ecosystem anyways — there's no benefit at all to using the standalone build.
另一方面,如果你正在进行一个项目,而不需要使用 Node.js 或 npm,那么独立构建版可能是一个很好的选择。如果 Tailwind 是你有 package.json 文件的唯一原因,那么这个方法可能会让你感觉更好。
🌐 If on the other hand you're working on a project where you don't otherwise need Node.js or npm, the standalone build can be a great choice. If Tailwind was the only reason you had a package.json file, this is probably going to feel like a nicer solution.