Git Product home page Git Product logo

tree-shakable-component-library's Introduction

Tree-shakable component library with TypeScript, StoryBook & Next.js

This repository is the demonstration of my dev.to article

๐Ÿ‘‰ https://dev.to/lukasbombach/how-to-write-a-tree-shakable-component-library-4ied

demonstrating how to implement a tree-shakable component library (with TypeScript, StoryBook & Next.js all in a Monorepo).

For questions you can find me on twitter as @luke_schmuke

Install

git clone https://github.com/LukasBombach/tree-shakable-component-library
cd tree-shakable-component-library
yarn

Run

This MonoRepo has 2 packages

The app is a Next.js app that consumes the ui-library in the index.tsx page while the ui-library provides bundled components.

You can run the app by switching to the app folder and run yarn dev or yarn start*
* both packages have postinstall script that runs yarn build in each project

Run the app

cd packages/app
yarn dev

You can also run StoryBook from within the ui-library

Run StoryBook

cd packages/ui-library
yarn storybook

You can change or add new components by running

Develop new components

cd packages/ui-library
yarn build -w

in another terminal you can run the app in parallel and it will auto-update with hot-module-reloading

cd packages/app
yarn dev

See the tree-shaking

You can very simple see that the app actually does tree-shake your code by opening this project in a code editor and searching all files in packages/app/.next and

  1. searching for the string I SHOULD BE HERE, which should be found. This string is part of the Button component which has been loaded into the app
  2. then search for the string I MUST NOT BE HERE This string is part of the Link component which has not been loaded into the app even though it has been bundled in the ui library and should not be bundled in the app.
  3. check out the file packages/ui-library/lib/index.esm.js which is the bundled file of the ui-library which includes all components

tree-shakable-component-library's People

Contributors

lukasbombach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tree-shakable-component-library's Issues

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.