GithubHelp home page GithubHelp logo

ui-lib-template's Introduction

ui-lib-template

react storybook rollup ui lib template

Tutorial

Init Package

npm init -y

Setup dependencies

npm install --save-dev react react-dom typescript @types/react postcss

Add peer dependencies

"peerDependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
}

Init typescript

npx tsc --init

and change the tsconfig.json to

{
   "compilerOptions": {
      "jsx": "react",
      "target": "es2016",
      "outDir": "dist",
      "allowJs": true,
      "skipLibCheck": true,
      "strict": true,
      "forceConsistentCasingInFileNames": true,
      "module": "ES2020",
      "allowSyntheticDefaultImports": true,
      "moduleResolution": "Node",
      "declaration": true,
      "declarationDir": "dist"
   },
   "include": [
      "stories"
   ]
}

Init storybook

npx sb init

Bundling

npm i --save-dev rollup 

and all the plugin you need to install

{
    "@rollup/plugin-babel": "^5.3.1",
    "@rollup/plugin-commonjs": "^22.0.2",
    "@rollup/plugin-node-resolve": "^14.1.0",
    "@rollup/plugin-replace": "^4.0.0",
    "rollup-plugin-analyzer": "^4.0.0",
    "rollup-plugin-peer-deps-external": "^2.2.4",
    "rollup-plugin-postcss": "^4.0.2",
    "rollup-plugin-typescript2": "^0.34.0",
    "rollup-plugin-uglify": "^6.0.4",
    "rollup-plugin-visualizer": "^5.8.1",
}

copy the rollup.config.js

Export you lib

create entry point file index.ts

// Export all your components below
import { Button } from './stories/Button'
export { Button }

Using rollup

Add new command to your package.json file

{
    "buildLib": "rollup -c"
}

Publish

At this moment, you're good to publish your package to npm.

Please remember to change you package public by npm publish --access=public

Then add a namespace to your package @yourname/ui-lib

ui-lib-template's People

Contributors

discountry avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.