ui icon indicating copy to clipboard operation
ui copied to clipboard

using cli to add component with tsconfig reference doesn't work

Open devnomic opened this issue 2 years ago • 1 comments

I have tsconfig using references like:

{
  "files": [],
  "references": [{ "path": "./tsconfig.node.json" }, { "path": "./tsconfig.web.json" }],
}

However shadcn cli doesn't check reference path to look for component and utils alias. I think adding tsconfig path option to customize the tsconfig file path in components.json will solve the problem.

devnomic avatar Aug 13 '23 13:08 devnomic

I'm having the same issue, is there any way to resolve this?

dottodot avatar Mar 28 '24 21:03 dottodot

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Jul 05 '24 23:07 shadcn

It's maybe a good idea to prepare a dedicated script that utilizes the path option of the component addition command.

Add Script for Adding Components

Since the shadcn CLI does not support references in tsconfig.json, a dedicated command is created.

packages.json

"scripts": {
    "---- TOOL SECTION ----": "---- ---- ---- ---- ----",
    "add-component": "sh -c 'npx shadcn-ui@latest add \"$1\" -p src/renderer/src/components/shadcn/ui' --",
    "add-component-ps": "powershell -Command \"npx shadcn-ui@latest add $args[0] -p src/renderer/src/components/shadcn/ui\""  
}

add-component is for shell, add-component-ps is for PowerShell

Install Button

npm run add-component button

Usage Example

e.g.

import { Button } from '@renderer/components/ui/button';
import '@renderer/styles/globals.css';

function Home() {
  return (
    <>
      <Button variant="default" className="m-4">
        Button
      </Button>
    </>
  );
}

atman-33 avatar Aug 02 '24 15:08 atman-33