0.18.0 • Published 3 years ago

schenker.components v0.18.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Schenker Components

Local development

Run example app

In /example, a simple app is created to test local changes to components on the run. Import the component, and start the app by cd example and yarn start

Link to real App

Sometimes, we need to test the library in a real app. By using yarn link this could be pretty simple. However, this will may cause an error, where the App that uses the library will start complaining about two versions of react. There is a simple workaround which is implemented in this receipt.

Make sure you are in schenker.components by cd to it.

yarn link
yarn install
cd node_modules/react
yarn link
cd ../../node_modules/react-dom
yarn link
cd YOUR_PROJECT
yarn link schenker.components
yarn link react
yarn link react-dom

Any changes is this library will affect the App that has linked it in as a dependency.

Storybook

To watch all components, go ahead and start storybook. Here, all components should be exported (the developer should do this when developing a new component). Then you can tweek all the Props in the storybook.

Run inside another terminal:

yarn storybook

This loads the stories from ./stories.

NOTE: Stories should reference the components as if using the library, similar to the example playground. This means importing from the root project directory. This has been aliased in the tsconfig and the storybook webpack config as a helper.

Example usage

In your app, import both component and styling

import { Button } from "schenker.components";
import "schenker.components/dist/schenker.components.esm.css";

Configuration

Code quality is set up for you with prettier, husky, and lint-staged.

Jest

Jest tests are set up to run with npm test or yarn test.

Bundle analysis

Calculates the real cost of your library using size-limit with npm run size and visulize it with npm run analyze.

Rollup

TSDX uses Rollup as a bundler and generates multiple rollup configs for various module formats and build settings. See Optimizations for details.

TypeScript

tsconfig.json is set up to interpret dom and esnext types, as well as react for jsx. Adjust according to your needs.

Continuous Integration

GitHub Actions

Two actions are added by default:

  • main which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
  • size which comments cost comparison of your library on every pull request using size-limit

Optimizations

Please see the main tsdx optimizations docs. In particular, know that you can take advantage of development-only optimizations:

// ./types/index.d.ts
declare var __DEV__: boolean;

// inside your code...
if (__DEV__) {
  console.log('foo');
}

You can also choose to install and use invariant and warning functions.

Named Exports

Per Palmer Group guidelines, always use named exports. Code split inside your React app instead of your React library.

Including Styles

There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.

For vanilla CSS, you can include it at the root directory and add it to the files section in your package.json, so that it can be imported separately by your users and run through their bundler's loader.