Used in ncc while emitting and relocating any asset references
Installations
npm install @vercel/webpack-asset-relocator-loader
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
18.20.2
NPM Version
6.14.9
Score
95.1
Supply Chain
99.6
Quality
83.5
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
40,315,507
Last Day
19,946
Last Week
127,828
Last Month
852,438
Last Year
12,546,049
GitHub Statistics
101 Stars
316 Commits
33 Forks
52 Watching
7 Branches
82 Contributors
Bundle Size
476.31 kB
Minified
136.67 kB
Minified + Gzipped
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
40,315,507
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
23
Asset Relocator Loader for Webpack
Asset relocation loader used in ncc for performing Node.js builds while emitting and relocating any asset references.
Usage
Installation
1npm i -g @vercel/webpack-asset-relocator-loader
Usage
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 Permissions and Symlinks
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.
Caching
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});
How it Works
Asset Relocation
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.- File emissions for exact asset paths
- Whole directory asset emissions for exact directory paths
- Wildcard asset emissions for variable path expressions
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.
Binary Relocation
Node binary loading conventions cover the following triggers for binary relocations:
require('bindings')(...)
nbind.init(..)
node-pre-gyp
include patterns
Any shared libraries loaded by these binaries will also be emitted as well.
Node.js Compatibility Features
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 theutils/wrappers.js
file for the exact transformations currently provided.require.resolve
support in the target environment, while also supporting emission in the build environment.- Dynamic
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/vercel/.github/SECURITY.md:1
- Info: Found linked content: github.com/vercel/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/vercel/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/vercel/.github/SECURITY.md:1
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
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/prs.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/vercel/webpack-asset-relocator-loader/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/vercel/webpack-asset-relocator-loader/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/prs.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/vercel/webpack-asset-relocator-loader/prs.yml/main?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Reason
31 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-4r62-v4vq-hr96
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-x2pg-mjhr-2m5x
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-72mh-269x-7mh5
- Warn: Project is vulnerable to: GHSA-h4j5-c7cj-74xg
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
4.1
/10
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