All Projects โ†’ webdeveric โ†’ Webpack Assets Manifest

webdeveric / Webpack Assets Manifest

Licence: mit
This Webpack plugin will generate a JSON file that matches the original filename with the hashed version.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Webpack Assets Manifest

React Core Boilerplate
Powerful ASP.NET Core 3 templates with React, true server-side rendering and Docker support
Stars: โœญ 169 (-37.17%)
Mutual labels:  webpack, webpack-plugin
Wxapp Webpack Plugin
๐Ÿ“ฆ ๅพฎไฟกๅฐ็จ‹ๅบ webpack ๆ’ไปถ
Stars: โœญ 185 (-31.23%)
Mutual labels:  webpack, webpack-plugin
Html Res Webpack Plugin
plugin for generating html in webpack
Stars: โœญ 170 (-36.8%)
Mutual labels:  webpack, webpack-plugin
Virtual Module Webpack Plugin
Adds the contents of a virtual file to webpack's cached file system without writing it to disk
Stars: โœญ 165 (-38.66%)
Mutual labels:  webpack, webpack-plugin
Critters
๐Ÿฆ” A Webpack plugin to inline your critical CSS and lazy-load the rest.
Stars: โœญ 2,894 (+975.84%)
Mutual labels:  webpack, webpack-plugin
Webpack.js.org
Repository for webpack documentation and more!
Stars: โœญ 2,049 (+661.71%)
Mutual labels:  webpack, webpack-plugin
Emojify Webpack Plugin
๐Ÿฆ„ Turn your code into emoji
Stars: โœญ 178 (-33.83%)
Mutual labels:  webpack, webpack-plugin
Obsolete Webpack Plugin
๐ŸŒˆ A Webpack plugin generates a browser-side standalone script that detects browser compatibility based on `Browserslist` and prompts website users to upgrade it.
Stars: โœญ 148 (-44.98%)
Mutual labels:  webpack, webpack-plugin
Hard Source Webpack Plugin
www.npmjs.com/package/hard-source-webpack-plugin
Stars: โœญ 2,608 (+869.52%)
Mutual labels:  webpack, webpack-plugin
Unused Files Webpack Plugin
Glob all files that are not compiled by webpack under webpack's context
Stars: โœญ 210 (-21.93%)
Mutual labels:  webpack, webpack-plugin
Svg Spritemap Webpack Plugin
SVG spritemap plugin for webpack
Stars: โœญ 160 (-40.52%)
Mutual labels:  webpack, webpack-plugin
Webpack Messages
Beautifully format Webpack messages throughout your bundle lifecycle(s)!
Stars: โœญ 238 (-11.52%)
Mutual labels:  webpack, webpack-plugin
Clean Webpack Plugin
By default, this plugin will remove all files inside webpack's output.path directory, as well as all unused webpack assets after every successful rebuild.
Stars: โœญ 1,888 (+601.86%)
Mutual labels:  webpack, webpack-plugin
Multipage Webpack Plugin
A plugin that makes handling templates and asset distribution for multi-page applications using webpack trivial
Stars: โœญ 168 (-37.55%)
Mutual labels:  webpack, webpack-plugin
Webpack Babel Multi Target Plugin
A Webpack plugin that works with Babel to allow differential loading - production deployment of ES2015 builds targeted to modern browsers, with an ES5 fallback for legacy browsers.
Stars: โœญ 150 (-44.24%)
Mutual labels:  webpack, webpack-plugin
Workerize Loader
๐Ÿ—๏ธ Automatically move a module into a Web Worker (Webpack loader)
Stars: โœญ 2,135 (+693.68%)
Mutual labels:  webpack, webpack-plugin
Worker Plugin
๐Ÿ‘ฉโ€๐Ÿญ Adds native Web Worker bundling support to Webpack.
Stars: โœญ 1,840 (+584.01%)
Mutual labels:  webpack, webpack-plugin
Bundle Stats
In-depth bundle analyzer for webpack(bundle size, assets, modules, packages)
Stars: โœญ 144 (-46.47%)
Mutual labels:  webpack, webpack-plugin
Bundle Buddy Webpack Plugin
๐Ÿ๐Ÿ๐Ÿ๐Ÿ bundle-buddy-webpack-plugin ๐Ÿ๐Ÿ๐Ÿ๐Ÿ
Stars: โœญ 199 (-26.02%)
Mutual labels:  webpack, webpack-plugin
Copy Webpack Plugin
Copy files and directories with webpack
Stars: โœญ 2,679 (+895.91%)
Mutual labels:  webpack, webpack-plugin

Webpack Assets Manifest

Build Status codecov dependencies Status devDependencies Status

This webpack plugin will generate a JSON file that matches the original filename with the hashed version.

Installation

npm install webpack-assets-manifest --save-dev

New in version 5

  • Compatible with webpack 5 only (5.1+ required).
  • Supports finding asset modules.
  • Updated options schema to prevent additional properties. This helps with catching typos in option names.
  • โš ๏ธ Updated default value of the output option to be assets-manifest.json. This is to prevent confusion when working with Web app manifests or WebExtension manifests.

New in version 4

  • Requires Node 10+.

  • Compatible with webpack 4 only (4.40+ required).

  • Added options: enabled, entrypointsUseAssets, contextRelativeKeys.

  • Updated writeToDisk option to default to auto.

  • Use lock files for various operations.

  • done hook is now an AsyncSeriesHook.

  • โš ๏ธ The structure of the entrypoints data has been updated to include preload and prefetch assets. Assets for an entrypoint are now included in an assets property under the entrypoint.

    Example:

    {
      "entrypoints": {
        "main": {
          "assets": {
            "css": [
              "main.css"
            ],
            "js": [
              "main.js"
            ]
          },
          "prefetch": {
            "js": [
              "prefetch.js"
            ]
          },
          "preload": {
            "js": [
              "preload.js"
            ]
          }
        }
      }
    }
    

Usage

In your webpack config, require the plugin then add an instance to the plugins array.

const path = require('path');
const WebpackAssetsManifest = require('webpack-assets-manifest');

module.exports = {
  entry: {
    // Your entry points
  },
  output: {
    path: path.join( __dirname, 'dist' ),
    filename: '[name]-[hash].js',
    chunkFilename: '[id]-[chunkhash].js',
  },
  module: {
    // Your loader rules go here.
  },
  plugins: [
    new WebpackAssetsManifest({
      // Options go here
    }),
 ],
};

Sample output

{
  "main.js": "main-9c68d5e8de1b810a80e4.js",
  "main.css": "main-9c68d5e8de1b810a80e4.css",
  "images/logo.svg": "images/logo-b111da4f34cefce092b965ebc1078ee3.svg"
}

Options (read the schema)

enabled

Type: boolean

Default: true

Is the plugin enabled?

output

Type: string

Default: assets-manifest.json

This is where to save the manifest file relative to your webpack output.path.

assets

Type: object

Default: {}

Data is stored in this object.

Sharing data

You can share data between instances by passing in your own object in the assets option.

This is useful in multi-compiler mode.

const data = Object.create(null);

const manifest1 = new WebpackAssetsManifest({
  assets: data,
});

const manifest2 = new WebpackAssetsManifest({
  assets: data,
});

contextRelativeKeys

Type: boolean

Default: false

Keys are relative to the compiler context.

space

Type: int

Default: 2

Number of spaces to use for pretty printing.

replacer

Type: null, function, or array

Default: null

Replacer reference

You'll probably want to use the transform hook instead.

fileExtRegex

Type: regex

Default: /\.\w{2,4}\.(?:map|gz)$|\.\w+$/i

This is the regular expression used to find file extensions. You'll probably never need to change this.

writeToDisk

Type: boolean, string

Default: 'auto'

Write the manifest to disk using fs.

โš ๏ธ If you're using another language for your site and you're using webpack-dev-server to process your assets during development, you should set writeToDisk: true and provide an absolute path in output so the manifest file is actually written to disk and not kept only in memory.

sortManifest

Type: boolean, function

Default: true

The manifest is sorted alphabetically by default. You can turn off sorting by setting sortManifest: false.

If you want more control over how the manifest is sorted, you can provide your own comparison function. See the sorted example.

new WebpackAssetsManifest({
  sortManifest(a, b) {
    // Return -1, 0, or 1
  }
});

merge

Type: boolean, string

Default: false

If the output file already exists and you'd like to add to it, use merge: true. The default behavior is to use the existing keys/values without modification.

new WebpackAssetsManifest({
  output: '/path/to/manifest.json',
  merge: true
});

If you need to customize during merge, use merge: 'customize'.

If you want to know if customize was called when merging with an existing manifest, you can check manifest.isMerging.

new WebpackAssetsManifest({
  merge: 'customize',
  customize(entry, original, manifest, asset) {
    if ( manifest.isMerging ) {
      // Do something
    }
  },
}),

publicPath

Type: string, function, boolean,

Default: null

When using publicPath: true, your webpack config output.publicPath will be used as the value prefix.

const manifest = new WebpackAssetsManifest({
  publicPath: true,
});

When using a string, it will be the value prefix. One common use is to prefix your CDN URL.

const manifest = new WebpackAssetsManifest({
  publicPath: '//cdn.example.com',
});

If you'd like to have more control, use a function. See the custom CDN example.

const manifest = new WebpackAssetsManifest({
  publicPath(filename, manifest)
  {
    // customize filename here
    return filename;
  }
});

entrypoints

Type: boolean

Default: false

Include compilation.entrypoints in the manifest file.

entrypointsKey

Type: string, boolean

Default: entrypoints

If this is set to false, the entrypoints will be added to the root of the manifest.

entrypointsUseAssets

Type: boolean

Default: false

Entrypoint data should use the value from assets, which means the values could be customized and not just a string file path. This new option defaults to false so the new behavior is opt-in.

integrity

Type: boolean

Default: false

Include the subresource integrity hash.

integrityHashes

Type: array

Default: [ 'sha256', 'sha384', 'sha512' ]

Hash algorithms to use when generating SRI. For browsers, the currently the allowed integrity hashes are sha256, sha384, and sha512.

Other hash algorithms can be used if your target environment is not a browser. If you were to create a tool to audit your S3 buckets for data integrity, you could use something like this example to record the md5 hashes.

integrityPropertyName

Type: string

Default: integrity

This is the property that will be set on each entry in compilation.assets, which will then be available during customize. It is customizable so that you can have multiple instances of this plugin and not have them overwrite the currentAsset.integrity property.

You'll probably only need to change this if you're using multiple instances of this plugin to create different manifests.

apply

Type: function

Default: null

Callback to run after setup is complete.

customize

Type: function

Default: null

Callback to customize each entry in the manifest.

transform

Type: function

Default: null

Callback to transform the entire manifest.

done

Type: function

Default: null

Callback to run after the compilation is done and the manifest has been written.


Hooks

This plugin is using hooks from Tapable.

The apply, customize, transform, and done options are automatically tapped into the appropriate hook.

Name Type Callback signature
apply SyncHook function(manifest){}
customize SyncWaterfallHook function(entry, original, manifest, asset){}
transform SyncWaterfallHook function(assets, manifest){}
done AsyncSeriesHook async function(manifest, stats){}
options SyncWaterfallHook function(options){}
afterOptions SyncHook function(options){}

Tapping into hooks

Tap into a hook by calling the tap method on the hook as shown below.

If you want more control over exactly what gets added to your manifest, then use the customize and transform hooks. See the customized and transformed examples.

const manifest = new WebpackAssetsManifest();

manifest.hooks.apply.tap('YourPluginName', function(manifest) {
  // Do something here
  manifest.set('some-key', 'some-value');
});

manifest.hooks.customize.tap('YourPluginName', function(entry, original, manifest, asset) {
  // customize entry here
  return entry;
});

manifest.hooks.transform.tap('YourPluginName', function(assets, manifest) {
  // customize assets here
  return assets;
});

manifest.hooks.options.tap('YourPluginName', function(options) {
  // customize options here
  return options;
});

manifest.hooks.done.tap('YourPluginName', function(manifest, stats) {
  console.log(`The manifest has been written to ${manifest.getOutputPath()}`);
  console.log(`${manifest}`);
});

manifest.hooks.done.tapPromise('YourPluginName', async (manifest, stats) => {
  await yourAsyncOperation();
});

These hooks can also be set by passing them in the constructor options.

new WebpackAssetsManifest({
  done(manifest, stats) {
    console.log(`The manifest has been written to ${manifest.getOutputPath()}`);
    console.log(`${manifest}`);
  }
});

Manifest methods

If the manifest instance is passed to a hook, you can use the following methods to manage what goes into the manifest.

  • has(key)
  • get(key)
  • set(key, value)
  • setRaw(key, value)
  • delete(key)

If you want to write the manifest to another location, you can use writeTo(destination).

new WebpackAssetsManifest({
  async done(manifest) {
    await manifest.writeTo('/some/other/path/assets-manifest.json');
  }
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].