Skip to content

A Bun plugin that simplifies bundling NestJS applications by addressing issues with optional dependencies and missing Nest CLI compiler plugins, ensuring a smoother bundling process

Notifications You must be signed in to change notification settings

pmb0/bun-plugin-nestjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@pmb0/bun-plugin-nestjs

@pmb0/bun-plugin-nestjs is a Bun plugin designed to simplify the bundling process of NestJS applications. One key challenge is how NestJS checks for optional dependencies: It attempts to load them using require() (see this code snippet). If these dependencies are not installed, this approach typically leads to bundler errors.

@pmb0/bun-plugin-nestjs addresses this issue by marking any uninstalled dependencies as external, allowing the bundler to complete the process without failing due to missing dependencies.

Another challenge is that you can no longer rely on the Nest CLI and its associated compile-time steps. For example, compiler plugins from @nestjs/swagger won't run automatically. As a result, you'll need to manually add the necessary decorators to your code to ensure that metadata for Swagger and other tools is properly generated.

Other potential issues may arise depending on the specific tools or structure of your application. For instance, you might encounter difficulties with certain dynamic imports, reflection mechanisms, or loading module-related assets.

Getting Started

Add @pmb0/bun-plugin-nestjs to your dependencies.

bun add --dev @pmb0/bun-plugin-nestjs

Create a bun build script:

// build.ts
import { NestPlugin } from "@pmb0/bun-plugin-nestjs";

const out = await Bun.build({
  entrypoints: ["./src/main.ts"],
  format: "esm",
  minify: {
    identifiers: false,
    syntax: true,
    whitespace: true,
  },
  outdir: "/tmp/test",
  packages: "bundle",
  plugins: [NestPlugin],
  sourcemap: "linked",
  target: "node",
});

console.log("Build done", out.success ? "Success" : out);

Build the Nest app:

bun build.ts

About

A Bun plugin that simplifies bundling NestJS applications by addressing issues with optional dependencies and missing Nest CLI compiler plugins, ensuring a smoother bundling process

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published