A template to build TypeScript libraries with both Vanilla JavaScript and React entry points.
The goal of this template is to simplify the process of creating, maintaining, and publishing libraries. It provides a ready-to-use setup with sensible defaults, including an automated release workflow triggered on every push to the repository.
Using this library is straightforward:
Click the Use this template button to create a new repository based on this template.
Create an NPM_TOKEN repository secret in your new repository. The token must be a valid npm access token with read and write permissions. On top of that, it must bypass 2FA, as it is used in a CD workflow.
Note
Follow GitHub’s guide to create repository secrets.
Note
This token is required by the automated release workflow.
Edit the package.json file to reflect your library’s metadata:
name– Your library nameversion– Start at0.0.0description– Short and meaningful descriptionrepository– Repository URLauthor– Author informationbugs– Issue tracker URLhomepage– Project homepage (e.g. theREADME.mdlink)keywords– Relevant keywords for discoverability
Execute the following commands:
npm install
npm run devThis template comes with sample code inside the src folder.
The only important thing to notice is that every feature your library wants to export should be defined inside src/core/index.ts and src/react/index.ts.
Note
src/core/index.ts and src/react/index.ts are defined as the entry points of your library.
On top of that, every commit must follow this Conventional Commits format:
<type>(<scope>): <description> [<issue-number>]
Note
This is required by the release workflow, which analyzes every commit to automatically generate the releases.
This template includes a local development site under the dev folder.
Remove the dependencies from the package.json, and execute npm install ../. This will install the local library.
Update the sample code and visit http://localhost:5173/dev/ to check the implementation.
A sample Next.js demo site is included in the www folder.
Note
There is a GitHub Action that deploys it on every push.
To begin with, update the basePath setting inside the next.config.ts. It should match your repository slug (e.g. /my-repo-name/).
Then, you can update the sample code and visit http://localhost:3000/my-repo-name to check the implementation.
Finally, remember to enable GitHub Pages with GitHub Actions for your repository.
Update the README.md to describe your library’s purpose and usage.
Important
Don’t forget to update the release badge URL at the top of this file if you keep it — it currently points to this repository.
Note
To gain a deeper understanding of how to use this library and how it works under the hood, visit the wiki page.
Note
At the time of writing, it seems npm does not support fine-grained tokens for CD workflows. A recommended workaround is to publish the package once. For instance, using the CLI: npm login and npm publish. Then, create a token restricted to that specific package.
Note
There is a ticket to add testing tools to improve the library's validation workflow.
Detailed changes for each release are documented in CHANGELOG.md.
This work is published under MIT License.
Always happy to receive a greeting on: