Gathering detailed insights and metrics for @vercel/webpack-asset-relocator-loader
Gathering detailed insights and metrics for @vercel/webpack-asset-relocator-loader
Used in ncc while emitting and relocating any asset references
npm install @vercel/webpack-asset-relocator-loader
Typescript
Module System
Node Version
NPM Version
95.1
Supply Chain
99.6
Quality
83.5
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
40,315,507
Last Day
19,946
Last Week
127,828
Last Month
852,438
Last Year
12,546,049
101 Stars
316 Commits
33 Forks
52 Watching
7 Branches
82 Contributors
Minified
Minified + Gzipped
Latest Version
1.7.4
Package Id
@vercel/webpack-asset-relocator-loader@1.7.4
Unpacked Size
0.96 MB
Size
235.18 kB
File Count
5
NPM Version
6.14.9
Node Version
18.20.2
Publised On
16 May 2024
Cumulative downloads
Total Downloads
Last day
3.2%
19,946
Compared to previous day
Last week
-30.7%
127,828
Compared to previous week
Last month
-12.7%
852,438
Compared to previous month
Last year
-7.8%
12,546,049
Compared to previous year
1
23
Asset relocation loader used in ncc for performing Node.js builds while emitting and relocating any asset references.
1npm i -g @vercel/webpack-asset-relocator-loader
Add this loader as a Webpack plugin for any JS files.
Any .node
files included will also support binary relocation.
1{ 2 target: "node", 3 output: { 4 libraryTarget: "commonjs2" 5 }, 6 module: { 7 rules: [ 8 { 9 // For node binary relocations, include ".node" files as well here 10 test: /\.(m?js|node)$/, 11 // it is recommended for Node builds to turn off AMD support 12 parser: { amd: false }, 13 use: { 14 loader: '@vercel/webpack-asset-relocator-loader', 15 options: { 16 // optional, base folder for asset emission (eg assets/name.ext) 17 outputAssetBase: 'assets', 18 // optional, restrict asset emissions to only the given folder. 19 filterAssetBase: process.cwd(), 20 // optional, permit entire __dirname emission 21 // eg `const nonAnalyzable = __dirname` can emit everything in the folder 22 emitDirnameAll: false, 23 // optional, permit entire filterAssetBase emission 24 // eg `const nonAnalyzable = process.cwd()` can emit everything in the cwd() 25 emitFilterAssetBaseAll: false, 26 // optional, custom functional asset emitter 27 // takes an asset path and returns the replacement 28 // or returns false to skip emission 29 customEmit: (path, { id, isRequire }) => false | '"./custom-replacement"', 30 // optional, a list of asset names already emitted or 31 // defined that should not be emitted 32 existingAssetNames: [], 33 wrapperCompatibility: false, // optional, default 34 // build for process.env.NODE_ENV = 'production' 35 production: true, // optional, default is undefined 36 cwd: process.cwd(), // optional, default 37 debugLog: false, // optional, default 38 } 39 } 40 } 41 ] 42 } 43}
Assets will be emitted using emitAsset
, with their references updated in the code by the loader to the new output location.
Asset symlinks and permissions are maintained in the loader, but aren't passed to Webpack as emit
doesn't support these.
This information can be obtained from the loader through the API calls getAssetMeta()
and getSymlinks()
:
1const relocateLoader = require('webpack-asset-relocator-loader'); 2 3webpack({...}).run((err, stats) => { 4 const assetMeta = relocateLoader.getAssetMeta(); 5 const symlinks = relocateLoader.getSymlinks(); 6});
They will always contain the most recent build state.
When using Webpack 5 caching, asset permissions need to be maintained through their own cache, and the public path needs to be injected into the build.
To ensure these cases work out, make sure to run initAssetCache
in the build, with the options.outputAssetBase
argument:
1const relocateLoader = require('webpack-asset-relocator-loader'); 2 3webpack({ 4 // ... 5 6 plugins: [ 7 { 8 apply(compiler) { 9 compiler.hooks.compilation.tap("webpack-asset-relocator-loader", compilation => { 10 relocateLoader.initAssetCache(compilation, outputAssetBase); 11 }); 12 } 13 } 14 ] 15});
Assets are detected using static analysis of code, based on very specific triggers designed for common Node.js workflows to provide build support for a very high (but not perfect) level of compatibility with existing Node.js libraries.
process.cwd()
, __filename
, __dirname
, path.*()
, require.resolve
are all statically analyzed when possible.When an asset is emitted, the pure expression referencing the asset path is replaced with a new expression to the relocated asset and the asset emitted. In the case of wildcard emission, the dynamic parts of the expression are maintained.
Node binary loading conventions cover the following triggers for binary relocations:
require('bindings')(...)
nbind.init(..)
node-pre-gyp
include patternsAny shared libraries loaded by these binaries will also be emitted as well.
In addition to asset relocation, this loader also provides a couple of compatibility features for Webpack Node.js builds as part of its analysis.
These include:
require.main === module
checks are retained for the entry point being built.options.wrapperCompatibility
: Automatically handles common AMD / Browserify wrappers to ensure they are properly built by Webpack. See the utils/wrappers.js
file for the exact transformations currently provided.require.resolve
support in the target environment, while also supporting emission in the build environment.require
statements are analyzed to exact paths wherever possible, and when not possible to analyze, turned into dynamic requires in the target environment.No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 8/12 approved changesets -- score normalized to 6
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
31 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-06
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