
What We're Building
loader-overlay is a zero-dependency React component that renders a customisable overlay with animated loaders. Key features:
- 5 animation types: spinner, dots, pulse, ring, bar
- 5 overlay variants: dark, light, blur, transparent, gradient
- Progress bar with shimmer animation
- Outside-click dismissal
- Auto-dismiss timeout
- Full TypeScript support
- Zero runtime dependencies
Here's what the final API looks like:
jsx
Step 1 — Project Setup
Start by creating a new project folder and initialising it:
bash
Your initial package.json should look like:
json
The three key fields for a library are:
main— CommonJS build (for Node.js / older bundlers)module— ESM build (for modern bundlers like Vite/Webpack 5)types— TypeScript definitions file
Step 2 — Install Dependencies
bash
Add React as a peer dependency (not a dependency) in package.json so consumers use their own React version:
json
Step 3 — TypeScript Configuration
Create a tsconfig.json at the root:
json
Step 4 — Write the Component
Create src/index.tsx:
tsx
Tip: Export the props interface so consumers can type their own wrappers.
Step 5 — Rollup Build Config
Create rollup.config.js:
javascript
Add build scripts to package.json:
json
The prepublishOnly script automatically runs your build before every publish — so you never accidentally publish stale code.
Step 6 — Build and Test Locally
bash
To test locally in another project before publishing:
bash
Or use npm pack to simulate a real install:
bash
Step 7 — Write a Great README
A good README is crucial for npm package adoption. Include:
- Badge row — version, downloads, license, bundle size
- One-line description — what it does and why it's different
- Feature list — bullets with emojis for scannability
- Installation — all package managers
- Quick start — minimal working example
- Props table — every prop with type, default, description
- Advanced examples — real-world patterns
- TypeScript usage
markdown
Step 8 — Publish to npm
8.1 Create an npm Account
bash
8.2 Verify Package Name is Available
bash
If the name is taken, either scope it with your username or choose a new name:
json
8.3 Final Pre-publish Checklist
bash
Make sure files in package.json only includes dist/ and README.md:
json
8.4 Publish!
bash
You'll see output like:
npm notice 📦 loader-overlay@1.0.0
npm notice === Tarball Contents ===
npm notice 12.4kB dist/index.js
npm notice 11.8kB dist/index.esm.js
npm notice 2.1kB dist/index.d.ts
npm notice 4.2kB README.md
npm notice === Tarball Details ===
npm notice total files: 4
+ loader-overlay@1.0.0
Step 9 — Using with yarn and pnpm
Once published to npm, it's automatically available on yarn and pnpm since they both pull from the npm registry.
yarn
bash
pnpm
bash
pnpm uses a content-addressable store and hard links, so the package is only downloaded once across all projects on your machine.
bun
bash
Step 10 — Publishing Updates
Semantic Versioning
Follow semver: MAJOR.MINOR.PATCH
| Change | Version bump | Example |
|---|---|---|
| Bug fix | patch | 1.0.0 → 1.0.1 |
| New feature (non-breaking) | minor | 1.0.0 → 1.1.0 |
| Breaking change | major | 1.0.0 → 2.0.0 |
bash
Deprecating Old Versions
bash
Conclusion
You've now built and published a production-quality React component to npm. Here's a summary of what we covered:
- ✅ Project setup with
package.jsonfields for ESM + CJS - ✅ TypeScript config and interface exports
- ✅ Rollup build outputting both module formats
- ✅ Local testing with
npm linkandnpm pack - ✅ Writing a great README with badges and examples
- ✅ Publishing to npm with
--dry-runsafety checks - ✅ Availability on yarn, pnpm, and bun automatically
- ✅ Semantic versioning for updates
The package is now live at https://www.npmjs.com/package/loader-overlay and installable by anyone in the world.
Resources
- npm docs — Creating and publishing packages
- Rollup docs — Building with TypeScript
- Semantic Versioning
- npm semver calculator
- Bundlephobia — check your package size
Have questions? Open an issue on GitHub or reach out on Twitter.