Build a Component Library for React with Typescript [2021]

Поділитися
Вставка
  • Опубліковано 17 лис 2024

КОМЕНТАРІ • 74

  • @lucaford2598
    @lucaford2598 2 роки тому +2

    This video is perfect.
    Recommended 100%. You don't even realize how many issues you avoid only by following this steps.

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому

      Glad you liked it.

    • @lucaford2598
      @lucaford2598 2 роки тому

      ​@@TheNerdyCanuck hey! how are you?. me again.
      Can I ask you a question? if you want to add an .css file, like styles.css, you have to add some sort of a plugin transpiler, right? if you use TSC build and you have an .css file, when you want to import that project in another one as a library you get an error that the specific .css file couldn't be found. You know if you can sort this error with TSC or I should move to an standar webpack configuration? thanks. Great videos!

  • @rodrigonovais9624
    @rodrigonovais9624 2 роки тому +4

    14:40 Simpler override defaults:
    Object.assign(defaultOptions, options)
    You can also use Logical Assignment Operators, like:
    _styles.color ??= color

  • @farsal6271
    @farsal6271 Рік тому

    Great Tutorial, 17:25 npm install from local package was what i wish to find for writing some unit test.

  • @sabaashrafi-e3w
    @sabaashrafi-e3w Рік тому +1

    perfect, thanks a lot. you resolve my problem very well!!

  • @johnmark-ps8jy
    @johnmark-ps8jy 2 роки тому +2

    That's great man, i appreciate your work. Keep it up!

  • @justinwang9660
    @justinwang9660 6 місяців тому +1

    thank you. very nice toturial.

  • @ankitmehrotra8519
    @ankitmehrotra8519 2 роки тому +1

    Excellent tutorial. Learned a lot from it. Subscribed...:)

  • @parsa264
    @parsa264 6 місяців тому

    thank you, but how to use tailwind or sass for this library?

  • @sumitwadhwa8823
    @sumitwadhwa8823 2 роки тому +1

    Excellent video. Thanks for sharing.

  • @Minecraftzocker766
    @Minecraftzocker766 2 роки тому +1

    Many thanks for this great tutorial! 🙏🏼

  • @ALFREDVPAUL
    @ALFREDVPAUL Рік тому

    Nice!! can you explain how to work with theme Dark and Light mode.

  • @daniel84136
    @daniel84136 Рік тому +1

    Really great video. Thanks so much.

  • @gangstacoder4234
    @gangstacoder4234 7 місяців тому

    but how do you test while developing a library

  • @manudrlng1569
    @manudrlng1569 2 роки тому +1

    Thanks buddy, it was very helpful. 👍

  • @karlkrasnowsky3895
    @karlkrasnowsky3895 2 роки тому +1

    So close! This is by far the most straight forward approach to library creation, especially given a smaller sized library.
    After building a library using this approach, however, I found that I'm in need of including stylesheet (css) files in my component imports and the build as provided in this tutorial doesn't bundle them.
    Any hints on how I might be able to do this without resorting to a full rollup bundler?

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому +1

      Lol I was about to suggest rollup but let's avoid that.
      As far as I know, tsc won't compile / transfer over CSS, so the only clean work around is creating objects of type React.CSSPropeties and putting those in TS files.
      However, some people have 1k+ lines of CSS already, so I'll look into another way to get those CSS files over.
      I suspect we could write a script that executes and transfers the CSS over to the appropriate spots and try that (or keep the CSS somewhere common the like root folder)

    • @karlkrasnowsky3895
      @karlkrasnowsky3895 2 роки тому +1

      @@TheNerdyCanuck I started looking at styled-components and may continue, but yet one more concept to absorb. I just want css! 😆

    • @OswaldChisala
      @OswaldChisala Рік тому

      @@karlkrasnowsky3895 at my startup, we use tailwind. we compile the tailwind first, then import the resulting output.css file like "import 'output.css';" in a .ts file. then in package json, we specify the ts file in the "files" param (shown in this video at some point if I recall) and everything's good to go. To be fair, we don't actually build our ui package. Instead we use turbo to transpile it into a nextJS workspace package, and everything just works. hope this helps or gives you ideas. best wishes.

    • @parsa264
      @parsa264 6 місяців тому

      @@OswaldChisala how did you do that? how did you compile tailwind and used it in your package?

  • @caizer29
    @caizer29 Рік тому

    If I want to use tailwindcss both in my component library and in the projects that are consuming it, how do I do that?

  • @CodingIs-all
    @CodingIs-all Рік тому

    Please I'm getting this error, after installing it locally to a react app
    Cannot find module '25thandstaffing_ui' or its corresponding type declarations.

    • @namdgdhfjdj
      @namdgdhfjdj 9 місяців тому

      Did you find any fix for this?

  • @zlatkoiliev8927
    @zlatkoiliev8927 2 роки тому +1

    Great tutorial mate! Can you also show how can we add icons and tailwindcss, I guess we will need webpack for that?!? Also a storybook will be great to have too!

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому

      So I was investigating a way to do it without webpack or rollup or external tools but it's looking more and more like we need to use it.
      No big deal, I think I can make one like this to add css and extra assets (like icons, etc)

    • @zlatkoiliev8927
      @zlatkoiliev8927 2 роки тому

      @@TheNerdyCanuck I managed to do it by using copy-files and I run it after the build scripts, but the downside is we can only use pure css and it’s not minified.

  • @charansrinivas3149
    @charansrinivas3149 2 роки тому +2

    What about css files it wont get copied or transpiled or compiled . Is there any solution for this?

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому +1

      Personally I would write your CSS as typescript objects with the React.CSSProperties as it's type, but I can look into this for you.

    • @charansrinivas3149
      @charansrinivas3149 2 роки тому

      @@TheNerdyCanuck Thank you for your time.

    • @karlkrasnowsky3895
      @karlkrasnowsky3895 2 роки тому

      @@TheNerdyCanuck Interesting... so I too am looking at css/stylesheets and would be interested in this approach instead. However I can find little information on how to actually do this. Any pointers would be great.

  • @phiyoutube3422
    @phiyoutube3422 Рік тому

    can we use a Button from @mui/material/Button in this component library ?

  • @bo4695
    @bo4695 2 роки тому

    Thanks mate! Another great tutorial 🔥

  • @anirbansamaddar6214
    @anirbansamaddar6214 Рік тому

    Hello I don't know if anyone is going to reply to me or not but hoping they would I'm posting my comment. I'm using npm init the same process but what I'm trying to make contains mui card components. Now, I have written webpack config file ts config file in the root folder have exported all files in index.ts named entry point file , but still when i pack it says "interface" and "type" keyword is not recognised. I tried writing babel.config to fix this problem but it just excluded all the node modules that way and it became another problem overall. any suggestions on what to do when basic typescript keywords are not accepted. I even used babel loader and included all files in resolve part like ts and tsx and jsx.

  • @igordztv
    @igordztv 2 роки тому +1

    Really appreciate this!

  • @madmax4788
    @madmax4788 2 роки тому +3

    Omg what a great video. I watched this now I am hacking the Pentagon!

  • @scratchcoding7690
    @scratchcoding7690 2 роки тому +1

    This is called a tutorial man!!!

  • @vishwasvishu3282
    @vishwasvishu3282 Рік тому

    How to add ref for the components that we are created??

    • @TheNerdyCanuck
      @TheNerdyCanuck  8 місяців тому

      useRef I would imagine, but if you mean custom for our components, maybe I can make that in a future video

  • @prathapreddy244
    @prathapreddy244 Рік тому

    How do we compile assests, css/scss?

  • @stanleyfestus5599
    @stanleyfestus5599 2 роки тому +1

    Great video! I really thought rollup or webpack is a must. I have a problem though. I am publishing to npm with git but have error about using useState hooks. How can I fix this?

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому +1

      It's a must if you want to use CSS and other files

  • @manudrlng1569
    @manudrlng1569 2 роки тому +1

    when i am trying to use some image's and svg's its saying that webpackmodule missing, and if am using this className={classes.someClass} getting output just like this class=[object object] in another project can you help on this please

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому +1

      SO right now, it's only built for ts and tsx files. IN order to add other things like images and CSS, we have to use webpack or rollup. I will make a follow up to this video showing how to do that hopefully in the near future, this is just a boilerplate to get you started.

    • @prathapreddy244
      @prathapreddy244 Рік тому

      @@TheNerdyCanuck Do you have video yet regarding images, css loading?

  • @ravitandon9351
    @ravitandon9351 Рік тому

    Thank you! Well done!

  • @CodeDreamer68
    @CodeDreamer68 2 роки тому

    Would putting the react and react-dom in "peerDependencies" of the component library solve the problem of hooks you mentioned?

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому +1

      If you are referring to the problem of running it locally instead of installing it from source, no. You can try it though, if it works let me know!!

  • @neeswebservices
    @neeswebservices 2 роки тому +1

    How can we add MIT licence in it ?

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому

      You can google the MIT and add it to github or have github generate it for you :)

  • @tmnrp
    @tmnrp 2 роки тому +1

    Please also show how to publish the package

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому +1

      Sure, I can do that!

    • @tmnrp
      @tmnrp 2 роки тому

      @@TheNerdyCanuck Please also show how to add .css file as a bunlde part of a component

  • @somhrikkonar6147
    @somhrikkonar6147 2 роки тому

    hey, any update on how to use scss modules (style.module.scss)

  • @aalhommada5675
    @aalhommada5675 2 роки тому +1

    Thanks a lot ,

  • @irtazahussain8118
    @irtazahussain8118 2 роки тому

    I am on windows and whenever I try to run the build command it shows an error in the terminal.
    F:\Button>npm run build
    > button-adv@1.0.0 build
    > rm -rf dist/ && prettier --write src/ && npm run build:esm && npm run build:cjs
    'rm' is not recognized as an internal or external command,
    operable program or batch file.
    Will wait for your kind response.
    PS: I also used the del /s /q but after that i got another error
    F:\Button>npm run build
    > button-adv@1.0.0 build
    > del /s /q -rf dist/ && prettier --write src/ && npm run build:esm && npm run build:cjs
    Invalid switch - "".
    F:\Button>

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому +1

      Use git bash, command prompt and powershell use different commands than I used.

    • @balimuttajjofrancis1002
      @balimuttajjofrancis1002 Рік тому

      ​@@TheNerdyCanuck it has failed to work on my side as well

    • @balimuttajjofrancis1002
      @balimuttajjofrancis1002 Рік тому

      did u find a solution?

    • @parsa264
      @parsa264 6 місяців тому

      "build":"rmdir /s dist && npm run build:esm && npm run build:cjs",
      "build:esm":"npx tsc",
      "build:cjs":"npx tsc --module CommonJS --outDir dist/cjs",

  • @nazarkravchenko6891
    @nazarkravchenko6891 Рік тому +1

    thank you

  • @principe.borodin
    @principe.borodin 2 роки тому

    and add taiwind there?

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому

      I haven't gotten to it

    • @principe.borodin
      @principe.borodin 2 роки тому

      @@TheNerdyCanuck Your video resolved one my big problem. But, My typos aren't exported. Have you any trick? I believe that is because My types are written in different files of components files, but I exported all types =/

  • @rajshah2644
    @rajshah2644 2 роки тому

    Can you please tell me how can i add css or scss files?

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому +2

      You have to use something like rollup to package them for you. It can't be done this way unless you convert the css to actual objects in javascript.

    • @rajshah2644
      @rajshah2644 2 роки тому

      Thank You.

  • @ovshar_Sarabi
    @ovshar_Sarabi Рік тому

    i cant use this in windows:(

    • @parsa264
      @parsa264 6 місяців тому

      "build":"rmdir /s dist && npm run build:esm && npm run build:cjs",
      "build:esm":"npx tsc",
      "build:cjs":"npx tsc --module CommonJS --outDir dist/cjs",

  • @kamalkamals
    @kamalkamals 2 роки тому

    that s not good u need to add watch update on ur package because it s stupid run build every time u change any thing

  • @nishantsharma4427
    @nishantsharma4427 2 роки тому +1

    Amazing tutorial. I didn't know that we can't use hooks while testing our package locally and I spent a lot of time in fixing that issue. I have a question, can you please help me with the below error that I am getting? I tried many solutionsbut none of them worked.
    Module parse failed: Unexpected token (10:28)
    File was processed with these loaders:
    ./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
    You may need an additional loader to handle the result of these loaders.

    • @TheNerdyCanuck
      @TheNerdyCanuck  2 роки тому

      Possibly forgot to add it to your peer dependencies?

    • @ivobabailan3020
      @ivobabailan3020 2 роки тому

      You need rollup to bundle this library