🌐 Nodejs.cn

2024年8月 - npx shadcn init

完整的 CLI 重写,支持所有主要的 React 框架。

新的 CLI 现已可用。这是一次完整的重写,带来了许多新功能和改进。你现在可以使用 npx shadcn add 安装组件、主题、钩子、工具等。

🌐 The new CLI is now available. It's a complete rewrite with a lot of new features and improvements. You can now install components, themes, hooks, utils and more using npx shadcn add.

这是向你和你的 LLM 可以访问和使用的代码分发迈出的重要一步。

🌐 This is a major step towards distributing code that you and your LLMs can access and use.

  1. 首先,CLI 现在开箱即支持所有主要的 React 框架:Next.js、Remix、Vite 和 Laravel。并且当你初始化一个新应用时,我们会更新你现有的 Tailwind 文件,而不是覆盖它们。
  2. 一个组件现在可以自带它自己的依赖。例如手风琴组件,它可以定义自己的 Tailwind 关键帧。当你将它添加到你的项目中时,我们会相应地更新你的 tailwind.config.ts 文件。
  3. 你也可以使用 URL 安装远程组件。npx shadcn add https://acme.com/registry/navbar.json
  4. 我们还改进了 init 命令。它可以检测框架,甚至可以通过一个命令初始化一个全新的 Next.js 应用。npx shadcn init
  5. 我们创建了一个新的模式,你可以使用它来发布你自己的组件注册表。由于它支持 URL,你甚至可以用它来分发私有组件。
  6. 还有一些更新,例如更好的错误处理和 monorepo 支持。

你今天可以尝试新的 cli。

🌐 You can try the new cli today.

pnpm dlx shadcn init sidebar-01 login-01

更新你的项目

🌐 Update Your Project

要将现有项目更新为使用新的 CLI,请更新你的 components.json 文件以包含 componentsutilsuilibhooks 的导入别名。

🌐 To update an existing project to use the new CLI, update your components.json file to include import aliases for your components, utils, ui, lib and hooks.

components.json
{
  "$schema": "https://shadcn.nodejs.cn/schema.json",
  "style": "new-york",
  "tailwind": {
    // ...
  },
  "aliases": {
    "components": "@/components",
    "utils": "@/lib/utils",
    "ui": "@/components/ui",
    "lib": "@/lib",
    "hooks": "@/hooks"
  }
}

如果你使用不同的导入别名前缀,例如 ~,请将 @ 替换为你的前缀。

🌐 If you're using a different import alias prefix eg ~, replace @ with your prefix.