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 🙏

© 2025 – Pkg Stats / Ryan Hefner

esbuild-plugin-embed

v0.1.1

Published

A custom **esbuild plugin** to replace `readFileSync(SOME_STRING_LITERAL)` calls in your JavaScript/TypeScript code with the file's embedded content at build time.

Downloads

10

Readme

esbuild-plugin-embed

A custom esbuild plugin to replace readFileSync(SOME_STRING_LITERAL) calls in your JavaScript/TypeScript code with the file's embedded content at build time.

This is useful for embedding static files (like .txt, .json, or .md) directly into your bundled output, reducing runtime dependencies on the filesystem.

Features

  • Replace readFileSync calls with file content at build time.
  • Supports embedding any file type.
  • Configurable options:
    • Base directory (cwd) for resolving file paths.
    • Custom match function to decide which files to embed.
  • Works with both JavaScript and TypeScript projects.

Installation

npm install esbuild-plugin-embed

Usage

Setup the Plugin

Include the plugin in your esbuild configuration:

import esbuild from "esbuild";
import { EmbedFilePlugin } from "esbuild-plugin-embed";

esbuild
  .build({
    entryPoints: ["src/index.ts"], // Entry file for your project
    outfile: "dist/bundle.js", // Output file
    bundle: true,
    plugins: [
      EmbedFilePlugin({
        cwd: ".", // Base directory for resolving file paths (default: current directory)
        match: (filePath) => filePath.endsWith(".md"), // Embed only .md files
      }),
    ],
    platform: "node",
  })
  .catch(() => process.exit(1));

Example Code

In your source code (src/index.ts):

import fs from "fs";

// This will be replaced with the content of README.md
const readmeContent = fs.readFileSync("README.md");

console.log(readmeContent);

If README.md contains:

# Example Project

This is an example README.

The output will look like this after bundling:

const readmeContent = "# Example Project\n\nThis is an example README.\n";
console.log(readmeContent);

Plugin Options

cwd (optional)

Specifies the base directory for resolving file paths. Defaults to the current directory (".").

Example:

embedFilePlugin({ cwd: "./src" });

match (optional)

A function to determine which files should be embedded. It takes the file path as input and should return a boolean (true to embed, false to skip). Defaults to embedding all files.

Example:

embedFilePlugin({
  match: (filePath) => filePath.endsWith(".txt"), // Embed only .txt files
});

Why Use This Plugin?

  1. Embed static files into your bundled code to eliminate runtime file dependencies.
  2. Customize the embedding behavior with minimal configuration.
  3. Simplify distribution by bundling everything into a single file.

License

MIT

Contributing

Feel free to open issues or submit pull requests to improve this plugin. Contributions are always welcome!