Configuration

Subpath exports

Entry points, tree-shaking, ESM + CJS builds, and CDN usage.

The package ships entry points for search, analytics, email, and React. Import only the capability you need - the root @kelpclick/client re-exports those for convenience.

Entry points

Import pathContents
@kelpclick/clientcreateKelpClient, createAnalytics, createIdentity, createKelpSearch, createKelpEmail, errors, types, VERSION.
@kelpclick/client/searchcreateKelpSearch(config) - search and browse.
@kelpclick/client/analyticscreateAnalytics(options) and the event taxonomy types.
@kelpclick/client/emailcreateKelpEmail(options) - subscribe and unsubscribe.
@kelpclick/client/reactKelpProvider, useSearch, useBrowse, and the context hooks.
// Root - re-exports everything. Good for getting started.
import { createKelpClient } from '@kelpclick/client';

// Capability subpaths - import only what you need.
import { createKelpSearch } from '@kelpclick/client/search';
import { createAnalytics } from '@kelpclick/client/analytics';
import { createKelpEmail } from '@kelpclick/client/email';
import { KelpProvider, useSearch } from '@kelpclick/client/react';

Tree-shaking

Each subpath is an independent entry point with its own chunk. A bundler (Vite, esbuild, webpack 5+) that supports package exports will tree-shake unused subpaths automatically.

Typical size guidance:

  • /search - smallest; no analytics pipeline or React.
  • /analytics - adds the event buffer and transport.
  • /react - requires React 18+ as a peer dependency; includes the hooks and KelpProvider.
  • Root - pulls in the search and analytics surface.

If you only need search on a server-rendered page, import from @kelpclick/client/search instead of the root to avoid bundling React hooks and analytics code.

ESM and CJS

The package ships both ESM (.js) and CJS (.cjs) builds. Your bundler or runtime picks the right format automatically via the exports field in package.json:

// ESM (bundlers, native modules)
import { createKelpClient } from '@kelpclick/client';

// CJS (Node.js require, Jest without transform)
const { createKelpClient } = require('@kelpclick/client');

The type declarations ship alongside both builds (.d.ts files).

CDN

Load directly from a CDN without a build step. The +esm suffix on jsDelivr gives you the ESM bundle:

<script type="module">
  import { createKelpClient } from 'https://cdn.jsdelivr.net/npm/@kelpclick/client@latest/+esm';

  const kelp = createKelpClient({
    searchUrl: 'https://{TENANT_ID}-search.kelp.click',
    analyticsUrl: 'https://{TENANT_ID}-events.kelp.click',
    apiKey: 'kelp_...',
  });
</script>

Pin to a specific version in production rather than @latest:

<script type="module">
  import { createKelpClient } from 'https://cdn.jsdelivr.net/npm/@kelpclick/client@0.2.0/+esm';
</script>

On this page