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 bundle
  • types: Points to type definitions
  • files: Only publish dist/ folder

Step 2: Build

npm run build

Verify 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 publish

Step 4: Get CDN URLs

After publishing, your library is available via CDN:

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.ts

jsDelivr

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.ts

Step 5: Register in ReAPI

  1. Go to External Libraries in ReAPI
  2. Click Add Library
  3. 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
  4. Click Sync from URL
  5. Enable the library

Version Tags

https://unpkg.com/@your-org/test-lib@1.0.0/dist/build.umd.js

Latest (For Development)

https://unpkg.com/@your-org/test-lib@latest/dist/build.umd.js

Version Range

https://unpkg.com/@your-org/test-lib@^1.0.0/dist/build.umd.js

Updating

Patch Update (Bug Fix)

npm version patch  # 1.0.0 -> 1.0.1
npm publish

Then update ReAPI registration to @1.0.1.

Minor Update (New Features)

npm version minor  # 1.0.0 -> 1.1.0
npm publish

Major Update (Breaking Changes)

npm version major  # 1.0.0 -> 2.0.0
npm publish

Note: 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.js

Troubleshooting

404 Not Found

  • Wait 1-2 minutes after publish for CDN propagation
  • Verify package name and version on npmjs.com
  • Check file path matches files in 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=1234567890

Or wait for CDN cache to expire (usually 1-24 hours).