独立 CLI:无需 Node.js 即可使用 Tailwind CSS

Adam Wathan

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 的项目中变得更加困难,而且由于 RailsPhoenix 等工具默认都不再使用 npm,我们需要找到一种方法,让人们能够在这些项目中使用 Tailwind,而无需强迫他们采用完全独立的工具生态系统。

¥This has made it harder to integrate into projects where using npm isn't always common, and with tools like Rails and Phoenix both moving away from npm by default, we needed to find a way for people to use Tailwind in these projects without forcing them to adopt an entirely separate ecosystem of tooling.

今天,我们宣布推出全新的 standalone CLI build,它以一个独立的可执行文件的形式,为你提供 Tailwind CLI 的全部功能 - 无需 Node.js 或 npm。

¥Today we're announcing a new standalone CLI build that gives you the full power of Tailwind CLI in a self-contained executable — no Node.js or npm required.


开始(Get started)

¥Get started

要安装它,请从 GitHub 上的 latest release 获取适用于你平台的可执行文件,并确保授予其可执行权限:

¥To install it, grab the executable for your platform from the latest release on GitHub, making sure to give it executable permissions:

# 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

我们甚至打包了所有第一方插件的最新版本,因此如果你想在项目中使用它们,只需在 tailwind.config.js 文件中将它们 require 即可,就像在基于 Node 的项目中一样:

¥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?)

¥How does it work?

我们没有用 Rust 或其他什么语言重写 Tailwind(yet...) - 我们实际上使用的是 pkg,这是 Vercel 的一个非常酷的项目,它允许你将 Node.js 项目转换为可执行文件,无需安装 Node.js 即可运行,因为它将项目所需的所有部分直接打包到可执行文件中。

¥We didn't rewrite Tailwind in Rust or anything (yet...) — we're actually using pkg, a really cool project by Vercel that lets you turn a Node.js project into an executable that can be run without installing Node.js by bundling all of the parts your project needs right into the executable itself.

这使得你仍然可以使用具有 JavaScript 全部功能的 tailwind.config.js 文件,而不是像 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?)

¥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.

TailwindCSS v4.1 中文网 - 粤ICP备13048890号