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

no-bundle-scoper

v2.0.8

Published

An esbuild plugin handle the path alias(es) when you don't want to bundle your source file(s).

Downloads

20

Readme

npm version

no-bundle-scoper

An esbuild plugin for rewriting aliased imports in unbundled output.
Because node --no-bundler needs clean paths too.


✨ What does it do?

When using tsconfig aliases like @utils/*, and building with esbuild in bundle: false mode, the output will still contain raw aliased imports like:

import { log } from '@utils/logger';

This plugin rewrites those import paths in the final .js files into proper relative paths like:

import { log } from './utils/logger.js';

📦 Installation

pnpm add -D no-bundle-scoper

Or, if you're using npm or yarn:

npm install -D no-bundle-scoper
# or
yarn add -D no-bundle-scoper

🔌 Peer Dependencies

This plugin requires esbuild to be installed in your project:

pnpm add -D esbuild

🔧 Example usage with esbuild

in tsconfig.json

{
  "compilerOptions": {
    ...
    "baseUrl": ".", //
    "paths": {
      "@app/*": ["src/*"],
      "@app2": ["src/utils/app2.ts"]
    }
  }
}

in your build sript

import { build } from 'esbuild';
import { noBundleScoper } from 'no-bundle-scoper';

await build({
  entryPoints: ['src/index.ts'],
  outdir: 'dist', // REQUIRED! This plugin needs a fixed outdir.
  bundle: false, // yes, or why do you want to use this plugin????
  platform: 'node',
  target: 'esnext',
  format: 'esm',
  logLevel: 'info',
  metafile: true, // <-- THIS IS REQUIRED!
  plugins: [noBundleScoper()]
});

📌 metafile: true is required — the plugin relies on esbuild's metafile to rewrite imports accurately.


📦 Output Directory Requirement

This plugin currently requires esbuild's outdir option to locate your output files.
The outfile option is not supported yet, but may be considered in the future.


✅ When should you use this?

  • You're building a Node.js project with esbuild
  • You're using tsconfig paths / alias (like @/, ~, etc.)
  • You're building without bundling (bundle: false)
  • You want to run the output files directly with native ESM support (node --no-bundler)

❌ Not compatible tools

tsup, vite, rollup... and tools that bundle by default

These tools bundle by default, and they all have their own solution.
You won't need this plugin if you use them.


⚠ Limitations

This plugin is intentionally limited in scope to stay stable and focused.
It assumes you're working in a standard single-package setup with a clear inDir → outDir compilation structure.

✅ Assumptions

  • All source files are located inside a single directory (usually src/),
    defined via baseUrl in your tsconfig.json.

  • All compiled output goes into a single outDir,
    preserving the folder structure of your source directory.

  • Only aliases that resolve to files within your source tree (baseUrl) will be rewritten.
    Aliases resolving to files outside of either inDir or outDir will be skipped. This avoids broken imports due to missing .js output or nonstandard build setups.

  • This plugin does not touch external imports,
    including packages from node_modules, native modules (e.g. fs, path), or anything marked external: true by esbuild.


🚫 Unsupported features

  • Only the first path in each alias entry will be used.
    If you define fallback targets like:

    {
      "paths": {
        "@lib/*": ["src/lib/*", "src/legacy-lib/*"]
      }
    }

    Only the first one (src/lib/*) will be used for rewriting.
    Support for fallback resolution may be added in the future, but is currently not implemented.

  • Alias-to-alias (chained alias) resolution is not supported.
    I don't want to make this plugin fall into the void and become a black hole of unstable resolution logic.
    So no, no-bundle-scoper is not going to support it anytime soon.


⚠️ Important

This plugin will not handle:

  • Paths that resolve to files outside of your source tree (e.g., ../../shared/xxx.ts)
  • Outputs from external or custom build systems
  • Aliases pointing to already-compiled files (e.g., anything inside your dist/ folder)

If your project uses a multi-package structure (monorepo),
you must build each package separately and run this plugin within each subpackage.
It is intentionally not designed to resolve or transform imports across packages.

This keeps the plugin lightweight, predictable, and avoids unintended cross-package rewrites.


License

MIT