Support Absolute paths, TypeScript, SASS (SCSS) modules, StoryBook and Jest
Congrats! You just saved yourself hours of work. Let’s get you oriented with what’s here and how to use it.
If you’re new to TypeScript and React, checkout this handy cheatsheet
Template scaffolds your new library inside /src
.
The recommended workflow is to run in one terminal:
npm start # or yarn start
This builds to /dist
and runs the project in watch mode so any edits you save inside src
causes a rebuild to /dist
.
Then you can import your library in local project using such as Next:
import { ComponentName } from "{path-to-your-project}"
Then run either Storybook:
Run inside another terminal:
npm run storybook # or yarn storybook
This loads the stories from /**/*.stories.tsx
.
Run inside another terminal:
npm run test # or yarn test
This loads the tests from /**/*.test.tsx
.
Jest tests are set up to run with npm test
or yarn test
.
Calculates the real cost of your library using size-limit with npm run size
or yarn size
and visulize it with npm run analyze
or tarn analyze
.
This is the folder structure we set up for you:
/src
index.ts # This is main export, project won't work without it
/components # Your new react library
index.tsx # Your component
index.stories.tsx # Instructions for StoryBook
index.test.tsx # Tests for Jest
index.module.scss # Styles
/kekos # Another example of component
Template uses Rollup as a bundler and generates multiple rollup configs for various module formats and build settings.
tsconfig.json
is set up to interpret dom
and esnext
types, as well as react
for jsx
. Adjust according to your needs.
Two actions are added by default:
main
which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrixsize
which comments cost comparison of your library on every pull request using size-limit
CJS, ESModules, and UMD module formats are supported.
The appropriate paths are configured in package.json
and dist/index.js
accordingly. Please report if any issues are found.
There are many ways to ship styles, including with CSS-in-JS. Template 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.
We recommend using np.