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

@deviousm/rspack-manifest-plugin

v5.0.2

Published

A Rspack Plugin for generating Asset Manifests

Downloads

663

Readme

tests cover size libera manifesto

rspack-manifest-plugin

An Rspack plugin for generating an asset manifest.

:heart: Please consider Sponsoring shellscape (author of webpack-manifest-plugin)

Notice

This plugin is forked from rspack-contrib/rspack-manifest-plugin, which is a fork of shellscape/webpack-manifest-plugin.

The function of this plugin is basically the same as shellscape/webpack-manifest-plugin.

The only difference is that this plugin exposes stats to the generate function, which allows for more flexibility in generating the manifest and potentially provides data that is required to generate the manifest.

Change list:

  • It returns a few more things with the getStats() function.
  • Expose stats to the generate function.
  • Rename package to @deviousm/rspack-manifest-plugin

Requirements

@deviousm/rspack-manifest-plugin is an evergreen 🌲 module.

This module requires an Active LTS Node version (v12.0.0+) and Webpack v5.0.0.

Contributing

This repository leverages pnpm for dependency management.

To begin, please install pnpm:

$ npm install pnpm -g

Install

Using npm:

npm install @deviousm/rspack-manifest-plugin --save-dev

Usage

Create a rspack.config.js file:

const { RspackManifestPlugin } = require('@deviousm/rspack-manifest-plugin');
const options = { ... };

module.exports = {
	// an example entry definition
	entry: [ 'app.js'	],
  ...
  plugins: [
    new RspackManifestPlugin(options)
  ]
};

And run Rspack.

With the default options, the example above will create a manifest.json file in the output directory for the build. The manifest file will contain a map of source filenames to the corresponding build output file. e.g.

{
  "dist/batman.js": "dist/batman.1234567890.js",
  "dist/joker.js": "dist/joker.0987654321.js"
}

Options

assetHookStage

Type: Number Default: Infinity

If you need to consume the output of this plugin in another plugin, it can be useful to adjust the stage at which the manifest is generated. Pass a new stage to assetHookStage to change when the manifest is generated. See the docs on processAssets for more detail.

Note: any files added to the compilation after the stage specified will not be included in the manifest.

basePath

Type: String Default: ''

Specifies a path prefix for all keys in the manifest. Useful for including your output path in the manifest.

fileName

Type: String Default: manifest.json

Specifies the file name to use for the resulting manifest. By default the plugin will emit manifest.json to your output directory. Passing an absolute path to the fileName option will override both the file name and path.

filter

Type: Function Default: undefined

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

generate

Type: Function Default: undefined

A custom Function to create the manifest. The passed function should match the signature of (seed: Object, files: FileDescriptor[], stats: StatsCompilation, entries: string[]) => Object and can return anything as long as it's serialisable by JSON.stringify.

map

Type: Function Default: undefined

Allows modifying the files which make up the manifest. The passed function should match the signature of (file: FileDescriptor) => FileDescriptor where an object matching FileDescriptor is returned.

publicPath

Type: String Default: <webpack-config>.output.publicPath

A path prefix that will be added to values of the manifest.

removeKeyHash

Type: RegExp | false Default: /([a-f0-9]{32}\.?)/gi

If set to a valid RegExp, removes hashes from manifest keys. e.g.

{
  "index.c5a9bff71fdfed9b6046.html": "index.c5a9bff71fdfed9b6046.html"
}
{
  "index.html": "index.c5a9bff71fdfed9b6046.html"
}

The default value for this option is a regular expression targeting Webpack's default md5 hash. To target other hashing functions / algorithms, set this option to an appropriate RegExp. To disable replacing the hashes in key names, set this option to false.

seed

Type: Object Default: {}

A cache of key/value pairs used to seed the manifest. This may include a set of custom key/value pairs to include in your manifest, or may be used to combine manifests across compilations in multi-compiler mode. To combine manifests, pass a shared seed object to each compiler's RspackManifestPlugin instance.

serialize

Type: Function(Object) => string Default: undefined

A Function which can be leveraged to serialize the manifest in a different format than json. e.g. yaml.

sort

Type: Function Default: undefined

Allows sorting the files which make up the manifest. The passed function should match the signature of (fileA: FileDescriptor, fileB: FileDescriptor) => Number. Return 0 to indicate no change, -1 to indicate the file should be moved to a lower index, and 1 to indicate the file shoud be moved to a higher index.

useEntryKeys

Type: Boolean Default: false

If true, the keys specified in the entry property will be used as keys in the manifest. No file extension will be added (unless specified as part of an entry property key).

useLegacyEmit

Type: Boolean Default: false

If true, the manifest will be written on the deprecated webpack emit hook to be compatible with not yet updated webpack plugins.

A lot of webpack plugins are not yet updated to match the new webpack 5 API. This is a problem when other plugins use the deprecated emit hook. The manifest will be written before these other plugins and thus files are missing on the manifest.

writeToFileEmit

Type: Boolean Default: false

If true, will emit the manifest to the build directory and in memory for compatibility with webpack-dev-server.

Manifest File Descriptor

This plugin utilizes the following object structure to work with files. Many options for this plugin utilize the structure below.

{
  chunk?: Chunk;
  isAsset: boolean;
  isChunk: boolean;
  isInitial: boolean;
  isModuleAsset: boolean;
  name: string | null;
  path: string;
}

chunk

Type: Chunk

Only available if isChunk is true

isInitial

Type: Boolean

Is required to run you app. Cannot be true if isChunk is false.

isModuleAsset

Type: Boolean

Is required by a module. Cannot be true if isAsset is false.

Compiler Hooks

This plugin supports the following hooks via the getCompilerHooks export; afterEmit, beforeEmit. These hooks can be useful, e.g. changing manifest contents before emitting to disk.

getCompilerHooks

Returns: { afterEmit: SyncWaterfallHook, beforeEmit: SyncWaterfallHook }

Usage

const { getCompilerHooks } = require('rspack-manifest-plugin');

class BatmanPlugin {
  apply(compiler) {
    const { beforeEmit } = getCompilerHooks(compiler);

    beforeEmit.tap('BatmanPlugin', (manifest) => {
      return { ...manifest, name: 'hello' };
    });
  }
}

Notes

  • If using this plugin with webpack-clean and webpack-dev-server, please review this issue.

Attiribution

Special thanks to Dane Thurber, the original author of this plugin, without whom this plugin would not exist.

Meta

CONTRIBUTING

LICENSE (MIT)