🌐 Nodejs.cn

JavaScript

如何在 JavaScript 中使用 shadcn/ui

这个项目及其组件都是用 TypeScript 编写的。我们也建议在你的项目中使用 TypeScript。

🌐 This project and the components are written in TypeScript. We recommend using TypeScript for your project as well.

然而,我们也提供组件的 JavaScript 版本。JavaScript 版本可以通过 cli 获得。

🌐 However we provide a JavaScript version of the components as well. The JavaScript version is available via the cli.

要选择退出 TypeScript,你可以在你的 components.json 文件中使用 tsx 标志。

🌐 To opt-out of TypeScript, you can use the tsx flag in your components.json file.

components.json
{
  "style": "new-york",
  "rsc": false,
  "tsx": false,
  "tailwind": {
    "config": "",
    "css": "src/app/globals.css",
    "baseColor": "zinc",
    "cssVariables": true
  },
  "iconLibrary": "lucide",
  "aliases": {
    "components": "@/components",
    "utils": "@/lib/utils",
    "ui": "@/components/ui",
    "lib": "@/lib",
    "hooks": "@/hooks"
  }
}

要配置导入别名,你可以使用以下 jsconfig.json

🌐 To configure import aliases, you can use the following jsconfig.json:

jsconfig.json
{
  "compilerOptions": {
    "paths": {
      "@/*": ["./*"]
    }
  }
}