This TypeScript NPM package boilerplate is designed to kickstart the development of TypeScript libraries for Node.js and the browser. It features a modern build setup with TypeScript, leveraging tsup
for bundling and @changesets/cli
for version management. The package exports a simple function as an example to demonstrate the setup.
- TypeScript for type safety.
- Biome for linting and formatting.
- Dual package output (CommonJS and ESM) for compatibility.
- Type definitions for TypeScript projects.
- Automated build and release scripts.
- Node.js v22.5.1 (ensure you have this version by using
.nvmrc
) pnpm
(Follow pnpm installation guide if you haven't installed it)- Biome for linting and formatting
First, clone the existing repository simonorzel26/npm-package-boilerplate-2024
to your local machine. This step involves copying all the files from the original repository.
git clone https://github.com/simonorzel26/npm-package-boilerplate-2024.git <your-new-repository-name>
cd <your-new-repository-name>
Since you're creating a new project, you'll likely want to start with a clean history:
rm -rf .git
This command removes the .git
directory which contains all the git history of the original repository.
Now, initialize a new git repository:
git init
git add .
git commit -m "Initial commit based on npm-package-boilerplate-2024"
Go to GitHub and create a new repository named <your-new-repository-name>
. Do not initialize it with a README, .gitignore, or license since you are importing an existing project.
Link your local repository to the GitHub repository and push the changes:
git remote add origin https://github.com/<your-username>/<your-new-repository-name>.git
git branch -M main
git push -u origin main
Replace <your-username>
with your GitHub username.
To use this boilerplate for your project, clone the repository and install the dependencies.
pnpm install
After installation, you can start using the boilerplate to build your TypeScript library. Here's how to import and use the example function exported by this package:
import { foo } from 'your-package-name';
console.log(foo('Hello, world!'));
This package includes several scripts to help with development:
pnpm run build
: Compiles the TypeScript source code and generates both CommonJS and ESM modules along with type definitions.pnpm run lint
: Runs TypeScript compiler checks without emitting code to ensure type safety.pnpm run release
: Bundles the package and publishes it to NPM with version management.
To add a new function, create a .ts
file in the src
directory. For example:
// src/newFunction.ts
export const newFunction = (): void => {
// Implementation here
};
Then, export it from index.ts
:
// src/index.ts
export * from './newFunction';
Contributions are welcome! Please submit a pull request or create an issue for any features, bug fixes, or improvements.
This project is open-sourced under the MIT License. See the LICENSE file for more details.
Simon Orzel