npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pkl.js/react-sdk

v0.3.1

Published

Build tool for bundling react-pkl plugins

Readme

@pkl.js/react-sdk

Build tools for creating React PKL plugins.

Installation

npm install --save-dev @pkl.js/react-sdk

Usage

Basic Build

import { buildPlugin } from '@pkl.js/react-sdk';

await buildPlugin({
  entry: './src/index.tsx',
  outDir: './dist',
  meta: {
    id: 'com.example.plugin',
    name: 'My Plugin',
    version: '1.0.0',
    description: 'A sample plugin',
  },
});

This will:

  1. Bundle your plugin with esbuild
  2. Handle React/JSX transformation
  3. External React and React DOM
  4. Generate sourcemaps
  5. Output to dist/index.js

Advanced Configuration

await buildPlugin({
  entry: './src/index.tsx',
  outDir: './dist',
  meta: {
    id: 'com.example.plugin',
    name: 'My Plugin',
    version: '1.0.0',
  },
  
  // Output formats
  formats: ['esm', 'cjs'],
  
  // Minification
  minify: true,
  
  // Sourcemaps
  sourcemap: true,
  
  // Additional external dependencies
  external: ['lodash', 'axios'],
  
  // Custom esbuild plugins
  esbuildPlugins: [
    myCustomPlugin(),
  ],
  
  // Generate custom metadata
  generateMetadata: async (meta, outDir) => {
    const stats = await fs.stat(path.join(outDir, 'index.js'));
    return {
      ...meta,
      buildTime: new Date().toISOString(),
      size: stats.size,
      hash: await computeHash(outDir),
    };
  },
  
  // Metadata filename
  metadataFileName: 'plugin.json',
});

API

buildPlugin(config: PluginBuildConfig): Promise<PluginBuildResult>

Bundle a plugin with esbuild.

Config Options

interface PluginBuildConfig<TMeta = unknown> {
  // Required
  entry: string;              // Entry point path
  outDir: string;             // Output directory
  meta: TMeta;                // Plugin metadata

  // Optional
  formats?: Array<'esm' | 'cjs'>;  // Output formats (default: ['esm'])
  minify?: boolean;                 // Minify output (default: false)
  sourcemap?: boolean;              // Generate sourcemaps (default: true)
  external?: string[];              // External dependencies
  esbuildPlugins?: Plugin[];        // Custom esbuild plugins
  generateMetadata?: MetadataGenerator<TMeta>;
  metadataFileName?: string;        // Default: 'meta.json'
}

Result

interface PluginBuildResult<TMeta = unknown> {
  outDir: string;           // Resolved output directory
  outputFiles: string[];    // Generated file paths
  metadata?: TMeta;         // Generated metadata (if provided)
}

Examples

NPM Script

{
  "scripts": {
    "build": "node build.js"
  }
}
// build.js
import { buildPlugin } from '@pkl.js/react-sdk';

await buildPlugin({
  entry: './src/index.tsx',
  outDir: './dist',
  meta: {
    id: 'my-plugin',
    name: 'My Plugin',
    version: process.env.npm_package_version,
  },
  minify: process.env.NODE_ENV === 'production',
});

console.log('✅ Build complete!');

With CSS

// Your plugin imports CSS
import './styles.css';

// esbuild will bundle it automatically
await buildPlugin({
  entry: './src/index.tsx',
  outDir: './dist',
  meta: { /* ... */ },
});

Multiple Formats

await buildPlugin({
  entry: './src/index.tsx',
  outDir: './dist',
  meta: { /* ... */ },
  formats: ['esm', 'cjs'],
  // Generates: dist/index.esm.js and dist/index.cjs.js
});

Custom Metadata

await buildPlugin({
  entry: './src/index.tsx',
  outDir: './dist',
  meta: {
    id: 'my-plugin',
    name: 'My Plugin',
    version: '1.0.0',
  },
  generateMetadata: async (meta, outDir) => {
    const pkg = await readFile('./package.json', 'utf-8');
    const { dependencies } = JSON.parse(pkg);
    
    return {
      ...meta,
      buildTime: new Date().toISOString(),
      environment: process.env.NODE_ENV,
      dependencies,
    };
  },
});
// Writes: dist/meta.json

Features

  • ✅ Fast builds with esbuild
  • ✅ Automatic React/JSX transformation
  • ✅ CSS bundling and imports
  • ✅ Multiple output formats (ESM, CJS)
  • ✅ Sourcemap generation
  • ✅ Minification
  • ✅ Custom metadata generation
  • ✅ External dependency handling
  • ✅ Custom esbuild plugin support

Integration

With tsup

If you prefer tsup for bundling:

// tsup.config.ts
import { defineConfig } from 'tsup';

export default defineConfig({
  entry: ['src/index.tsx'],
  format: ['esm'],
  dts: true,
  sourcemap: true,
  external: ['react', 'react-dom'],
  outDir: 'dist',
});

With Vite

For development with Vite:

// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
  build: {
    lib: {
      entry: './src/index.tsx',
      formats: ['es'],
      fileName: 'index',
    },
    rollupOptions: {
      external: ['react', 'react-dom'],
    },
  },
});

Documentation