Gathering detailed insights and metrics for webpack-assets-manifest
Gathering detailed insights and metrics for webpack-assets-manifest
Gathering detailed insights and metrics for webpack-assets-manifest
Gathering detailed insights and metrics for webpack-assets-manifest
This webpack plugin will generate a JSON file that matches the original filename with the hashed version.
npm install webpack-assets-manifest
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
325 Stars
203 Commits
34 Forks
5 Watching
10 Branches
8 Contributors
Updated on 14 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-16.4%
118,516
Compared to previous day
Last week
-2.8%
690,946
Compared to previous week
Last month
6.1%
2,999,202
Compared to previous month
Last year
-12.6%
37,249,211
Compared to previous year
1
30
This webpack plugin will generate a JSON file that matches the original filename with the hashed version.
1pnpm add -D webpack-assets-manifest
1npm install webpack-assets-manifest -D
1yarn add webpack-assets-manifest -D
output
option to be assets-manifest.json
.
This is to prevent confusion when working with Web app manifests or WebExtension manifests.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
.
:warning: 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:
1{ 2 "entrypoints": { 3 "main": { 4 "assets": { 5 "css": ["main.css"], 6 "js": ["main.js"] 7 }, 8 "prefetch": { 9 "js": ["prefetch.js"] 10 }, 11 "preload": { 12 "js": ["preload.js"] 13 } 14 } 15 } 16}
In your webpack config, require the plugin then add an instance to the plugins
array.
1const path = require("path"); 2const WebpackAssetsManifest = require("webpack-assets-manifest"); 3 4module.exports = { 5 entry: { 6 // Your entry points 7 }, 8 output: { 9 path: path.join(__dirname, "dist"), 10 filename: "[name]-[hash].js", 11 chunkFilename: "[id]-[chunkhash].js", 12 }, 13 module: { 14 // Your loader rules go here. 15 }, 16 plugins: [ 17 new WebpackAssetsManifest({ 18 // Options go here 19 }), 20 ], 21};
1{ 2 "main.js": "main-9c68d5e8de1b810a80e4.js", 3 "main.css": "main-9c68d5e8de1b810a80e4.css", 4 "images/logo.svg": "images/logo-b111da4f34cefce092b965ebc1078ee3.svg" 5}
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.
You can share data between instances by passing in your own object in the assets
option.
This is useful in multi-compiler mode.
1const data = Object.create(null);
2
3const manifest1 = new WebpackAssetsManifest({
4 assets: data,
5});
6
7const manifest2 = new WebpackAssetsManifest({
8 assets: data,
9});
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
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
.
:warning: 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.
1new WebpackAssetsManifest({
2 sortManifest(a, b) {
3 // Return -1, 0, or 1
4 },
5});
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.
1new WebpackAssetsManifest({
2 output: "/path/to/manifest.json",
3 merge: true,
4});
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
.
1new WebpackAssetsManifest({
2 merge: 'customize',
3 customize(entry, original, manifest, asset) {
4 if ( manifest.isMerging ) {
5 // Do something
6 }
7 },
8}),
publicPath
Type: string
, function
, boolean
,
Default: null
When using publicPath: true
, your webpack config output.publicPath
will be used as the value prefix.
1const manifest = new WebpackAssetsManifest({
2 publicPath: true,
3});
When using a string, it will be the value prefix. One common use is to prefix your CDN URL.
1const manifest = new WebpackAssetsManifest({
2 publicPath: "//cdn.example.com",
3});
If you'd like to have more control, use a function. See the custom CDN example.
1const manifest = new WebpackAssetsManifest({ 2 publicPath(filename, manifest) { 3 // customize filename here 4 return filename; 5 }, 6});
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.
You can use this to customize entry names for example. In the sample below, we adjust img
keys so that it's easier to use them with a template engine:
1new WebpackAssetsManifest({ 2 customize(entry) { 3 if (entry.key.startsWith('img/')) { 4 return { key: entry.key.split('img/')[1], value: entry.value }; 5 } 6 7 return o; 8 } 9}
The function is called per each entry and provides you a way to intercept and rewrite each object. The result is then merged into a whole manifest.
View the example to see what else you can do with this function.
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.
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){} |
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.
1const manifest = new WebpackAssetsManifest(); 2 3manifest.hooks.apply.tap("YourPluginName", function (manifest) { 4 // Do something here 5 manifest.set("some-key", "some-value"); 6}); 7 8manifest.hooks.customize.tap( 9 "YourPluginName", 10 function (entry, original, manifest, asset) { 11 // customize entry here 12 return entry; 13 } 14); 15 16manifest.hooks.transform.tap("YourPluginName", function (assets, manifest) { 17 // customize assets here 18 return assets; 19}); 20 21manifest.hooks.options.tap("YourPluginName", function (options) { 22 // customize options here 23 return options; 24}); 25 26manifest.hooks.done.tap("YourPluginName", function (manifest, stats) { 27 console.log(`The manifest has been written to ${manifest.getOutputPath()}`); 28 console.log(`${manifest}`); 29}); 30 31manifest.hooks.done.tapPromise("YourPluginName", async (manifest, stats) => { 32 await yourAsyncOperation(); 33});
These hooks can also be set by passing them in the constructor options.
1new WebpackAssetsManifest({ 2 done(manifest, stats) { 3 console.log(`The manifest has been written to ${manifest.getOutputPath()}`); 4 console.log(`${manifest}`); 5 }, 6});
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)
.
1new WebpackAssetsManifest({
2 async done(manifest) {
3 await manifest.writeTo("/some/other/path/assets-manifest.json");
4 },
5});
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
14 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More