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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@better-builds/package-bundler

v1.6.1

Published

A CLI for compiling and bundling your TypeScript with ESM/CJS and deep exports support, `package-bundler` builds and bundles TypeScript packages in a style similar to `@apollo/client` and `@mui/material`, with support for deep exports to allow consumers t

Downloads

86

Readme

@better-builds/package-bundler

A CLI for compiling and bundling your TypeScript with ESM/CJS and deep exports support, package-bundler builds and bundles TypeScript packages in a style similar to @apollo/client and @mui/material, with support for deep exports to allow consumers to pick and choose imports they want. Not all imports are essential to a library, and some may carry expensive third party dependencies.

package-bundler will read your directory structure and produce a CJS bundle export for each subdirectory, and an ESM export for each sub-directory and file.

package-bundler uses esbuild to transpile TypeScript to JavaScript in both CommonJS and ESM formats. package-bundler also produces *.d.ts files so you can ship proper typings with your package, all with zero-to-minimal configuration.

used by

Netflix

installation

npm

npm install @better-builds/package-bundler -D

yarn

yarn add @better-builds/package-bundler -D

pnpm

pnpm add @better-builds/package-bundler -D

usage

package-bundler is meant to be used exclusively from within a TypeScript codebase. It also makes some assumptions about your codebase, namely, that each folder in your source code contains a proper index.ts or index.tsx file that imports and / or exports anything that is needed. Without this index.ts or index.tsx file, Package Bundler will only be able to emit a valid ESM module. CommonJS compilation and bundling will not work without these index files!

examples

Checkout the three examples in the examples folder

cli

package-bundler --help

Options:
      --version             Show version number                        [boolean]
  -c, --copyPackageJson     If true, copies the package json for the package to
                            the outDir. Useful if you are using yarn, pnpm,
                            lerna, or some other non vanilla NPM way of
                            publishing your packages. [boolean] [default: false]
  -e, --external            Marks one or more packages or file paths as
                            external, and that these packages or paths should
                            not be included in the build. For more information,
                            see ESBuild's official documentation:
                            https://esbuild.github.io/api/#external
                                                           [array] [default: []]
  -i, --ignorePaths         Array of file glob paths to exclude in the source(s)
                            being compiled. If you like these defaults, want to
                            keep them, but also provide your own, you can set
                            the --mergeIgnorePaths to have your paths merged
                            with these.
  [array] [default: ["**/*__doc**/**","**/*__test**/**","**/*__stori**/**","**/*
     .spec.*","**/*.test.*","**/*.stories.*","**/*.story.*","**/*__snipp**/**"]]
      --mergeIgnorePaths    If true, merges any provided paths you've set via
                            --ignorePaths with package-bundler's default ones.
                                                      [boolean] [default: false]
  -o, --outDir              Path to targeted publish directory relative to your
                            package working directory.
                                                    [string] [default: "./dist"]
  -p, --packageJsonFiles    An array of all of the package.json file locations
                            that contain dependencies for your package. The
                            dependencies listed in these package.json files will
                            be excluded from the CommonJS build (they are
                            automatically excluded from the ESM build).
                                                               [array] [default:
         ["/home/bduran/Documents/dev/opensource/package-bundler/package.json"]]
      --platform            Which ESBuild platform to target for the build.
           [string] [choices: "browser", "node", "neutral"] [default: "browser"]
  -r, --rewritePackageJson  If true, and used in conjunction with
                            ---copyPackageJson option, will attempt to inject
                            and / or rewrite the "main," "module," "typings,"
                            etc fields to where their paths exist in the
                            --outDir folder           [boolean] [default: false]
      --sourcemap           If true, builds sourcemap files alongside your
                            compiled files             [boolean] [default: true]
  -s, --srcDir              Path to src directory relative to your package
                            working directory.       [string] [default: "./src"]
      --target              Compilation target for the outputted JavaScript
                                                   [array] [default: ["es2018"]]
  -t, --tsconfigPath        Path to your tsconfig project file relative to your
                            package working directory.
                                           [string] [default: "./tsconfig.json"]
      --help                Show help                                  [boolean]

plugins

esbuild supports plugins for adapting builds to your needs. package-bundler allows you to provide your own plugins to enrich the sensible defaults provided by package-bundler. To do this, you can create a file named package-bundler.plugins.cjs (NOTE the .cjs extension) in your repository (or whenever your CWD will be when building with package-bundler). This file should have the following format:

module.exports = {
  /**
   * (Optional) Place all CommonJS-specific plugins here. These will *only*
   * apply to the CommonJS-compiled code
   */
  cjs: [],
  /**
   * (Optional) Place all ESM-specific plugins here. These will *only*
   * apply to the ESM-compiled code
   */
  esm: [],
};

Here's a real-world example that adds support for PostCSS, AutoPrefixer and also inlines images into both CJS and ESM builds

const autoprefixer = require('autoprefixer');
const postCssPlugin = require('@deanc/esbuild-plugin-postcss');
const inlineImage = require('esbuild-plugin-inline-image');

module.exports = {
  cjs: [postCssPlugin({ plugins: [autoprefixer] }), inlineImage()],
  esm: [postCssPlugin({ plugins: [autoprefixer] }), inlineImage()],
};

contributing

This repository was built using Node 18.13.0 and npm 9.3.0. Please be sure you have those installed before contributing and issuing a PR. Thanks!

Similar projects