Giter VIP home page Giter VIP logo

timmikeladze / tsup-react-package-starter Goto Github PK

View Code? Open in Web Editor NEW
151.0 4.0 13.0 3.38 MB

๐Ÿ“ฆ Develop & publish React or Typescript packages with ease. PostCSS, Vitest & Storybook support out of the box. Integrates with Github releases and automatically publishes to NPM. Code is built using tsup.

License: MIT License

JavaScript 43.60% Shell 5.54% TypeScript 49.77% CSS 1.09%
react-boilerplate react-package react-starter starter-kit starter-project tsup package-starter tsup-starter react storybook

tsup-react-package-starter's Introduction

๐Ÿ“ฆ React โ€ข Typescript โ€ข Package Starter

A slightly opinionated starter kit for developing React and/or TypeScript packages. It comes with a several pre-configured tools, so you could focus on coding instead of configuring a project for the nth time. From building to releasing a package, this starter kit has you covered.

๐Ÿ‘‹ Hello there! Follow me @linesofcode or visit linesofcode.dev for more cool projects like this one.

๐Ÿƒ Getting started

npx degit TimMikeladze/tsup-react-package-starter my-package

cd my-package && git init

pnpm install && pnpm dev

โ—Important note: This project uses pnpm for managing dependencies. If you want to use another package manager, remove the pnpm-lock.yaml and control-f for usages of pnpm in the project and replace them with your package manager of choice. If you don't have pnpm installed and want to use it, you can install it by running npm install -g pnpm.

What's included?

  • โšก๏ธtsup - The simplest and fastest way to bundle your TypeScript libraries. Used to bundle package as ESM and CJS modules. Supports TypeScript, Code Splitting, PostCSS, and more out of the box.
  • ๐Ÿ“– Storybook - Build UI components and pages in isolation. It streamlines UI development, testing, and documentation.
  • ๐Ÿงช Vitest - A testing framework for JavaScript. Preconfigured to work with TypeScript and JSX.
  • ๐Ÿ”ผ Release-it - release-it is a command line tool to automatically generate a new GitHub Release and populates it with the changes (commits) made since the last release.
  • ๐Ÿ™ Test & Publish via Github Actions - CI/CD workflows for your package. Run tests on every commit plus integrate with Github Releases to automate publishing package to NPM and Storybook to Github Pages.
  • ๐Ÿ“„ Commitizen โ€” When you commit with Commitizen, you'll be prompted to fill out any required commit fields at commit time.
  • ๐Ÿถ Husky โ€” Run scripts before committing.
  • ๐Ÿšซ lint-staged โ€” Run linters on git staged files
  • ๐Ÿค– Dependabot - Github powered dependency update tool that fits into your workflows. Configured to periodically check your dependencies for updates and send automated pull requests.
  • โ˜‘๏ธ ESLint - A linter for JavaScript. Includes a simple configuration for React projects based on the recommended ESLint and AirBnB configs.
  • ๐ŸŽจ Prettier - An opinionated code formatter.
  • ๐Ÿƒโ€โ™€๏ธโ€โžก๏ธ TSX - Execute TypeScript files with zero-config in a Node.js environment.

Usage

๐Ÿ’ป Developing

Watch and rebuild code with tsup and runs Storybook to preview your UI during development.

pnpm dev

Run all tests and watch for changes

pnpm test

๐Ÿ—๏ธ Building

Build package with tsup for production.

pnpm build

โ–ถ๏ธ Running files written in TypeScript

To execute a file written in TypeScript inside a Node.js environment, use the tsx command. This will detect your tsconfig.json and run the file with the correct configuration. This is perfect for running custom scripts while remaining type-safe.

pnpm tsx ./path/to/file.ts

This is useful for running scripts, starting a server, or any other code you want to run while remaining type-safe.

๐Ÿ–‡๏ธ Linking

Often times you want to link this package to another project when developing locally, circumventing the need to publish to NPM to consume it.

In a project where you want to consume your package run:

pnpm link my-package --global

Learn more about package linking here.

๐Ÿ“ฉ Committing

When you are ready to commit simply run the following command to get a well formatted commit message. All staged files will automatically be linted and fixed as well.

pnpm commit

๐Ÿ”– Releasing, tagging & publishing to NPM

Create a semantic version tag and publish to Github Releases. When a new release is detected a Github Action will automatically build the package and publish it to NPM. Additionally, a Storybook will be published to Github pages.

Learn more about how to use the release-it command here.

pnpm release

When you are ready to publish to NPM simply run the following command:

pnpm publish

๐Ÿค– Auto publish after Github Release (or manually by dispatching the Publish workflow)

โ—Important note: in order to automatically publish a Storybook on Github Pages you need to open your repository settings, navigate to "Actions" and enable "Read & write permissions" for Workflows. Then navigate to "Pages" and choose "GitHub Actions" as the source for the Build and Deployment. After a successful deployment you can find your Storybook at https://<your-github-username>.github.io/<your-repository-name>/.

โ—Important note: in order to publish package to NPM you must add your token as a Github Action secret. Learn more on how to configure your repository and publish packages through Github Actions here.

๐ŸŽจ CSS & PostCSS

Import CSS files works out of the box. Simply import your CSS files in your components and they will be bundled with your package.

tsup supports PostCSS out of the box. Simply run pnpm add postcss -D add a postcss.config.js file to the root of your project, then add any plugins you need. Learn more how to configure PostCSS here.

Additionally consider using the tsup configuration option injectStyle to inject the CSS directly into your Javascript bundle instead of outputting a separate CSS file.

๐Ÿš€ Built something using this starter-kit?

That's awesome! Feel free to add it to the list.

  • โœ… mui-joy-confirm - Confirmation dialogs built on top of @mui/joy and react hooks.
  • ๐Ÿ” next-auth-mui - Sign-in dialog for NextAuth built with MUI and React. Detects configured OAuth and Email providers and renders buttons or input fields for each respectively. Fully themeable, extensible and customizable to support custom credential flows.
  • ๐Ÿ—ƒ๏ธ next-upload - Turn-key solution for signed & secure file-uploads to an S3 compliant storage service such as R2, AWS, or Minio. Built for Next.js.
  • ๐Ÿ“ฎ next-invite - A drop-in invite system for your Next.js app. Generate and share invite links for users to join your app.
  • ๐ŸŒ space-slug - Generate unique slugs and usernames using an intuitive api with zero dependencies.
  • ๐Ÿ—‚๏ธ use-file-system - A set of React hooks to interact with the File System API. Watch a directory for changes and return a map of filepaths & contents when a file is added, modified or removed.
  • โ™พ๏ธ react-infinite-observer - A simple hook to implement infinite scroll in react component, with full control over the behavior. Implemented with IntersectionObserver.

tsup-react-package-starter's People

Contributors

dependabot[bot] avatar renovate-bot avatar renovate[bot] avatar seiry avatar timmikeladze 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tsup-react-package-starter's Issues

Not working with hooks

Hey, adding hooks to this example does't work.

Chage Example.tsx to:

import React, { useState } from 'react';

export type ExampleProps = {
  text?: String;
};

export function Example(props: ExampleProps) {
  const [state, setState] = useState(false);

  return <div>{props.text}</div>;
}

image

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

  • chore(deps): update all non-major dependencies (@babel/core, @babel/preset-env, @types/node, @types/react, @types/react-dom, @typescript-eslint/eslint-plugin, @typescript-eslint/parser, bitovi/github-actions-storybook-to-github-pages, eslint, eslint-plugin-react, eslint-plugin-typescript-sort-keys, typescript, yaml)

Detected dependencies

github-actions
.github/workflows/main.yml
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/publish.yml
  • actions/checkout v4
  • actions/setup-node v4
  • bitovi/github-actions-storybook-to-github-pages v1.0.2
npm
package.json
  • @babel/core 7.23.9
  • @babel/preset-env 7.23.9
  • @babel/preset-react 7.23.3
  • @babel/preset-typescript 7.23.3
  • @commitlint/cli 19.0.3
  • @commitlint/config-conventional 19.0.3
  • @ryansonshine/commitizen 4.2.8
  • @ryansonshine/cz-conventional-changelog 3.3.4
  • @storybook/addon-essentials 7.6.17
  • @storybook/addon-interactions 7.6.17
  • @storybook/addon-links 7.6.17
  • @storybook/blocks 7.6.17
  • @storybook/react 7.6.17
  • @storybook/react-webpack5 7.6.17
  • @storybook/testing-library 0.2.2
  • @testing-library/jest-dom 6.4.2
  • @testing-library/react 14.2.1
  • @types/node 20.11.19
  • @types/react 18.2.57
  • @types/react-dom 18.2.19
  • @types/react-test-renderer 18.0.7
  • @typescript-eslint/eslint-plugin 7.0.2
  • @typescript-eslint/parser 7.0.2
  • @vitejs/plugin-react 4.2.1
  • @vitest/coverage-v8 1.3.1
  • babel-loader 9.1.3
  • concurrently 8.2.2
  • eslint 8.56.0
  • eslint-config-airbnb 19.0.4
  • eslint-config-prettier 9.1.0
  • eslint-plugin-import 2.29.1
  • eslint-plugin-jsx-a11y 6.8.0
  • eslint-plugin-prefer-arrow 1.2.3
  • eslint-plugin-prettier 5.1.3
  • eslint-plugin-react 7.33.2
  • eslint-plugin-react-hooks 4.6.0
  • eslint-plugin-sort-class-members 1.20.0
  • eslint-plugin-storybook 0.8.0
  • eslint-plugin-typescript-sort-keys 3.1.0
  • eslint-plugin-unused-imports 3.1.0
  • husky 9.0.11
  • jsdom 24.0.0
  • lint-staged 15.2.2
  • prettier 3.2.5
  • prop-types 15.8.1
  • react 18.2.0
  • react-dom 18.2.0
  • react-test-renderer 18.2.0
  • release-it 17.1.1
  • storybook 7.6.17
  • ts-node 10.9.2
  • tsconfig-paths 4.2.0
  • tsup 8.0.2
  • typescript 5.3.3
  • vitest 1.3.1
  • yalc 1.0.0-pre.53
  • react >=17
  • react-dom >=17
  • node >=14.0.0
  • glob-parent >=5.1.2
  • parse-url >=8.1.0
  • semver >=7.5.2
  • trim >=0.0.3
  • trim-newlines >=3.0.1
  • yaml >=2.2.2

  • Check this box to trigger a request for Renovate to run again on this repository

'React' must be in scope when using JSX

11:3 error 'React' must be in scope when using JSX react/react-in-jsx-scope

I am encountering the above issue when building a component that does not import React (if I still import React babel is commenting out that import). I'd appreciate some hint on how to solve this. Many thanks!

Styles?

Am I missing something or is styling completely ignored in this setup? I like the setup but am unable to make .css or .scss work.

I'm trying to extend with postcss and tsup but so far no result. Do you have any examples on how to implement it using this setup?

Post CSS issues

Hi, when I tried to run this project based on the docs, I got this error:

image

[0]
[0]   The plugin "postcss" was triggered by this import
[0]
[0]     src/Example.tsx:1:7:
[0]       1 โ”‚ import './Example.css';
[0]         โ•ต        ~~~~~~~~~~~~~~~
[0]
[0] DTS Build start
[0] ESM Build failed
[0] Error: Build failed with 1 error:

I think it's a postCSS issue, if that's the case it would be great to add the related command in the getting started code to make it clearer for people, or at least having a comment about it.

SCSS Not working

  • Is there a way to to include scss? Do you have a guide for that?

CSS issue in released package

Hello, I have now successfully released my package ibcs-charts. the original Example component is also still there and can be imported. The CSS styles have been lost however. Would you know the reason?

Many thanks!

Critical dependency vulnerability from `storybook-deployer`

Thanks for the wonderful template ๐Ÿ‘

Currently there's a critical vulnerability when running npm install ๐Ÿ‘‡

image

And it's coming from @storybook/storybook-deployer which is deprecated (check archived repo here)

Solution

We can simply remove @storybook/storybook-deployer from the dependencies and it will clear all vulnerabilities.

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.