NPM & CDN Deployment
Deploy your library to npm and access it via CDN.
Prerequisites
- npm account (npmjs.com)
- Package name available (or scoped:
@your-org/test-lib)
Step 1: Configure package.json
{
"name": "@your-org/test-lib",
"version": "1.0.0",
"main": "dist/build.umd.js",
"types": "dist/build.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "rollup -c",
"prepublishOnly": "npm run build"
}
}Key fields:
main: Points to UMD bundletypes: Points to type definitionsfiles: Only publishdist/folder
Step 2: Build
npm run buildVerify output:
ls -la dist/
# build.umd.js (your bundle)
# build.d.ts (type definitions)Step 3: Publish
# Login (first time)
npm login
# Publish public package
npm publish --access public
# Or for scoped private (requires paid npm)
npm publishStep 4: Get CDN URLs
After publishing, your library is available via CDN:
unpkg (Recommended)
https://unpkg.com/@your-org/test-lib@1.0.0/dist/build.umd.js
https://unpkg.com/@your-org/test-lib@1.0.0/dist/build.d.tsjsDelivr
https://cdn.jsdelivr.net/npm/@your-org/test-lib@1.0.0/dist/build.umd.js
https://cdn.jsdelivr.net/npm/@your-org/test-lib@1.0.0/dist/build.d.tsStep 5: Register in ReAPI
- Go to External Libraries in ReAPI
- Click Add Library
- Enter:
- Title: Your Test Library
- Library URL:
https://unpkg.com/@your-org/test-lib@1.0.0/dist/build.umd.js - Library Name:
MyTestLib - Type URL:
https://unpkg.com/@your-org/test-lib@1.0.0/dist/build.d.ts
- Click Sync from URL
- Enable the library
Version Tags
Specific Version (Recommended for Production)
https://unpkg.com/@your-org/test-lib@1.0.0/dist/build.umd.jsLatest (For Development)
https://unpkg.com/@your-org/test-lib@latest/dist/build.umd.jsVersion Range
https://unpkg.com/@your-org/test-lib@^1.0.0/dist/build.umd.jsUpdating
Patch Update (Bug Fix)
npm version patch # 1.0.0 -> 1.0.1
npm publishThen update ReAPI registration to @1.0.1.
Minor Update (New Features)
npm version minor # 1.0.0 -> 1.1.0
npm publishMajor Update (Breaking Changes)
npm version major # 1.0.0 -> 2.0.0
npm publishNote: Update ReAPI registration and notify QA team of breaking changes.
Scoped Packages
For organization packages:
{
"name": "@acme/test-lib",
"publishConfig": {
"access": "public"
}
}URL becomes:
https://unpkg.com/@acme/test-lib@1.0.0/dist/build.umd.jsTroubleshooting
404 Not Found
- Wait 1-2 minutes after publish for CDN propagation
- Verify package name and version on npmjs.com
- Check file path matches
filesin package.json
CORS Errors
unpkg and jsDelivr both support CORS. If you see CORS errors:
- Verify URL is correct
- Check for typos in package name
Old Version Cached
# unpkg: Add ?v=timestamp to bust cache
https://unpkg.com/@your-org/test-lib@1.0.0/dist/build.umd.js?v=1234567890Or wait for CDN cache to expire (usually 1-24 hours).