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

tsup-plugin-prepend-directive

v0.1.2

Published

A tsup plugin that allows users to specify directives to be explicitly prepended to build files.

Readme

tsup-plugin-prepend-directive

This plugin is designed to be a lightweight dependency that allows users to specify directives they want prepended to specific build files that come out of tsup.

The advantage of this plugin is that it still works with tsup's code splitting and minifier which can cause other solutions that handle directives to fail. Code splitting can be especially desirable for library authors who want to reduce their overall bundle size and efficiency.

This plugin is primarily useful for including the "use client" directive, but is generalized to work for any directive.

Usage

To install:

npm install -D tsup-plugin-prepend-directive

Example

Below is an example of how this plugin can be used to specify a group of dist files we want prepended with "use client" while leaving other files that are safe for server-side use unchanged. In this example, we can enable both minificaiton and code splitting without issue.

// tsup.config.ts

const commonBundleConfig: Options = {
  target: 'esnext',
  platform: 'browser',
  clean: true,
  dts: false,
  minify: true,
}

const commonTypesConfig: Options = {
  target: 'esnext',
  dts: { only: true },
}

const configs: Options[] = [
  {
    name: 'build',
    splitting: true,
    // Code split shared code across the core and react packages
    entry: {
      'core': 'packages/core/src/index.ts',
      'react': 'packages/react/src/index.ts',
    },
    format: ['esm', 'cjs'],
    plugins: [prependDirective('"use client"', ['dist/react'])], // Tells the plugin to prepend "use client" directive to all resulting dist files matching 'dist/react*' path.
    ...commonBundleConfig,
  },
  {
    name: 'core-types',
    entry: {
      'core': 'packages/core/src/index.ts',
    },
    ...commonTypesConfig,
  },
  {
    name: 'react-types',
    entry: {
      'react': 'packages/react/src/index.ts',
    },
    ...commonTypesConfig,
  },
]

export default defineConfig(configs)

Motivation

The idea is that certain directives, such as "use client" must be present at the top of a module file. For library authors in particular, this poses unique challenges as during the build process, tsup can fail to place directives at the top of the module, or sometimes remove the directives altogether. It becomes additionally frustrating with code-splitting enabled as other plugins or "banner" solutions still can fail to get "use client" at the very top of the resulting build modules.

An example use-case would be someone authoring a library they wish to distribute that contains both interfaces they want to be available to the server, and client-only React components. Using this plugin, the user can configure tsup to still leverage tsup's code-splitting to reduce total bundle size while also specifying exactly which dist files should be marked with use-client.