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

esbuild-plugin-manifest

v1.0.5

Published

Plugin for esbuild to generate asset manifest.json file

Downloads

56,762

Readme

esbuild-plugin-manifest

Release Version Node.js CI codecov

This plugin will generate a manifest.json file, mapping original asset names to their corresponding output name.

Install

npm install --save-dev esbuild esbuild-plugin-manifest

Usage

Create file build.js:

const esbuild = require('esbuild');
const manifestPlugin = require('esbuild-plugin-manifest')

esbuild.build({
    entryPoints: ['src/index.js'],
    bundle: true,
    outdir: 'output/',
    plugins: [manifestPlugin()],
}).catch((e) => console.error(e.message))

This will generate a manifest.json in the output directory with a mapping of all the unhashed filenames to their corresponding hashed output filename:

{
  "output/index.js": "output/index-4QTUNIID.js"
}

Options

options.hash

Type: Boolean

Default: true

By default we assume that you want to hash the output files. We use [dir]/[name]-[hash] as the default hash format. You can disable hashing by setting this to false or you can set your own hash format by directly using esbuild's entryNames option.

options.shortNames

Type: Boolean | 'input' | 'output'

Default: false

By default we will use the full input and output paths {"output/index.js":"output/index-4QTUNIID.js"}, but when this option is enabled it will use the basename of the files {"index.js":"index-4QTUNIID.js"}

options.extensionless

Type: Boolean | 'input' | 'output'

Default: false

We'll keep all file extensions by default, but you can specify true to remove them from both or one of 'input' or 'output' to only remove them from the input or output respectively. Eg: specifying manifestPlugin({ extensionless: 'input' }) will result in {"output/index":"output/index-4QTUNIID.js"}

options.filename

Type: String

Default: manifest.json

The name of the generated manifest file in the output directory.

options.generate

Type: Function

Default: undefined

A custom Function to create the manifest. The passed function should match the signature of (entries: {[key: string]: string}) => Object; and can return anything as long as it's serialisable by JSON.stringify.

options.filter

Type: Function

Default: undefined

Allows filtering the files which make up the manifest. The passed function should match the signature of (filename: string) => boolean. Return true to keep the file, false to remove the file.

options.useEntrypointKeys

Type: Boolean

Default: false

By default, we use the same extension of the output file as the keys of the manifest key entry. Use this option if you'd rather use the input file (entrypoint) as the manifest key instead.

options.append

Type: Boolean

Default: false

By default, we will overwrite the manifest file if it already exists. This option will append to the existing manifest file instead and only overwrite the entries that have changed.

Advanced Usage Examples

Typescript Entrypoint

// build.js
const esbuild = require('esbuild');
const manifestPlugin = require('esbuild-plugin-manifest')

esbuild.build({
  entryPoints: ['src/index.ts'],
  bundle: true,
  outdir: 'output/',
  plugins: [manifestPlugin()],
}).catch((e) => console.error(e.message))
// manifest.json
{
  "output/index.js": "output/index-4QTUNIID.js"
}

Entrypoint Keys (.ts file example)

// build.js
const esbuild = require('esbuild');
const manifestPlugin = require('esbuild-plugin-manifest')

esbuild.build({
  entryPoints: ['src/index.ts'],
  bundle: true,
  outdir: 'output/',
  plugins: [manifestPlugin({useEntrypointKeys: true})],
}).catch((e) => console.error(e.message))
// manifest.json
{
  "src/index.ts": "output/index-4QTUNIID.js"
}

Multiple Formats

To generate multiple files from the same entrypoint with esbuild, you need to run it multiple times. Utilize esbuilds outExtension option along with our append option to generate multiple files from the same entrypoint.

// build.js
import * as esbuild from 'esbuild'
import manifestPlugin from 'esbuild-plugin-manifest'

await esbuild.build({
  entryPoints: ['src/index.js'],
  bundle: true,
  outdir: 'output/',
  format: 'cjs',
  plugins: [manifestPlugin()],
}).catch((e) => console.error(e.message))

await esbuild.build({
  entryPoints: ['src/index.js'],
  bundle: true,
  outdir: 'output/',
  format: 'esm',
  outExtension: { '.js': '.mjs' },
  plugins: [manifestPlugin({ append: true })],
}).catch((e) => console.error(e.message))
// manifest.json
{
  "output/index.js": "output/index-4QTUNIID.js",
  "output/index.mjs": "output/index-5RUVOJJE.mjs"
}