{"name":"@vercel/webpack-asset-relocator-loader","version":"1.10.3","license":"MIT","_id":"@vercel/webpack-asset-relocator-loader@1.10.3","maintainers":[{"name":"matheuss","email":"matheus.frndes@gmail.com"},{"name":"matt.straka","email":"matt.j.straka@gmail.com"},{"name":"vercel-release-bot","email":"infra+release@vercel.com"},{"name":"zeit-bot","email":"team@zeit.co"}],"homepage":"https://github.com/vercel/webpack-asset-relocator-loader#readme","bugs":{"url":"https://github.com/vercel/webpack-asset-relocator-loader/issues"},"dist":{"shasum":"6b0b6ebf15b23ff44c9bfc364cf7adfe3a2a07a5","tarball":"http://registry-npm.ywwl.com/@vercel/webpack-asset-relocator-loader/download/@vercel/webpack-asset-relocator-loader-1.10.3.tgz","fileCount":13,"integrity":"sha512-G8jCqUKGsgvzHA1R9SAh2pzMT/Cea5BKmx1C3ng18ykLWj58o9PXWt9Fj8fO4b5GRwezR1Btib1DbQ6pByxb5g==","signatures":[{"sig":"MEUCIQDsRWQQz0njmqoAjs0psQ9XCllXyiAOGnAuf9fXsjyXoAIgX/Hj7TGXIIDvoeFrG2M4Dnvx+vALsEZrtbfxqdKEO+8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@vercel%2fwebpack-asset-relocator-loader@1.10.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":118639,"size":26542,"noattachment":false,"key":"/@vercel/webpack-asset-relocator-loader/-/@vercel/webpack-asset-relocator-loader-1.10.3.tgz"},"main":"./src/asset-relocator.js","gitHead":"b9e42cd0004d6add1bd61dcc5620f68fc4af1712","scripts":{"test":"jest","test-pnp":"yarn pack -f test/yarn-pnp/assets-plugin-tarball.tgz && cd test/yarn-pnp && echo '' > yarn.lock && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install && yarn run build && yarn run test","test-coverage":"jest --coverage --globals \"{\\\"coverage\\\":true}\""},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:d9e79077-a920-47a9-8e9b-a9364af967fe"}},"repository":{"url":"git+https://github.com/vercel/webpack-asset-relocator-loader.git","type":"git"},"_npmVersion":"11.19.0","description":"Asset relocation loader used in ncc for performing Node.js builds while emitting and relocating any asset references.","directories":{},"_nodeVersion":"22.23.2","dependencies":{"glob":"^7.1.3","acorn":"^8.3.0","resolve":"^1.10.0","bindings":"^1.4.0","graceful-fs":"^4.1.15","loader-utils":"^1.2.3","magic-string":"^0.25.1","resolve-from":"3.0.0","estree-walker":"^0.6.1","node-gyp-build":"^4.8.4","sourcemap-codec":"^1.4.4","acorn-class-fields":"^1.0.0","rollup-pluginutils":"^2.8.2","@mapbox/node-pre-gyp":"^2.0.0","acorn-static-class-features":"^1.0.0","acorn-private-class-elements":"^1.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e","devDependencies":{"jest":"^26.6.3","webpack":"^5","memory-fs":"^0.4.1","@vercel/ncc":"^0.38.1","webpack-cli":"^4","semantic-release":"^25.0.9","socket.io-client":"^2.2.0"},"_npmOperationalInternal":{"tmp":"tmp/webpack-asset-relocator-loader_1.10.3_1786586701406_0.33373420246871266","host":"s3://npm-registry-packages-npm-production"},"readme":"# Asset Relocator Loader for Webpack\n\nAsset relocation loader used in ncc for performing Node.js builds while emitting and relocating any asset references.\n\n## Usage\n\n### Installation\n```bash\nnpm i -g @vercel/webpack-asset-relocator-loader\n```\n\n### Usage\n\nAdd this loader as a Webpack plugin for any JS files.\n\nAny `.node` files included will also support binary relocation.\n\n```js\n{\n  target: \"node\",\n  output: {\n    libraryTarget: \"commonjs2\"\n  },\n  module: {\n    rules: [\n      {\n        // For node binary relocations, include \".node\" files as well here\n        test: /\\.(m?js|node)$/,\n        // it is recommended for Node builds to turn off AMD support\n        parser: { amd: false },\n        use: {\n          loader: '@vercel/webpack-asset-relocator-loader',\n          options: {\n            // optional, base folder for asset emission (eg assets/name.ext)\n            outputAssetBase: 'assets',\n            // optional, restrict asset emissions to only the given folder.\n            filterAssetBase: process.cwd(),\n            // optional, permit entire __dirname emission\n            // eg `const nonAnalyzable = __dirname` can emit everything in the folder\n            emitDirnameAll: false,\n            // optional, permit entire filterAssetBase emission\n            // eg `const nonAnalyzable = process.cwd()` can emit everything in the cwd()\n            emitFilterAssetBaseAll: false,\n            // optional, custom functional asset emitter\n            // takes an asset path and returns the replacement\n            // or returns false to skip emission\n            customEmit: (path, { id, isRequire }) => false | '\"./custom-replacement\"',\n            // optional, a list of asset names already emitted or\n            // defined that should not be emitted\n            existingAssetNames: [],\n            wrapperCompatibility: false, // optional, default\n            // build for process.env.NODE_ENV = 'production'\n            production: true, // optional, default is undefined\n            cwd: process.cwd(), // optional, default\n            debugLog: false, // optional, default\n          }\n        }\n      }\n    ]\n  }\n}\n```\n\nAssets will be emitted using `emitAsset`, with their references updated in the code by the loader to the new output location.\n\n### Asset Permissions and Symlinks\n\nAsset symlinks and permissions are maintained in the loader, but aren't passed to Webpack as `emit` doesn't support these.\n\nThis information can be obtained from the loader through the API calls `getAssetMeta()` and `getSymlinks()`:\n\n```js\nconst relocateLoader = require('webpack-asset-relocator-loader');\n\nwebpack({...}).run((err, stats) => {\n  const assetMeta = relocateLoader.getAssetMeta();\n  const symlinks = relocateLoader.getSymlinks();\n});\n```\n\nThey will always contain the most recent build state.\n\n### Caching\n\nWhen 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.\n\nTo ensure these cases work out, make sure to run `initAssetCache` in the build, with the `options.outputAssetBase` argument:\n\n```js\nconst relocateLoader = require('webpack-asset-relocator-loader');\n\nwebpack({\n  // ...\n\n  plugins: [\n    {\n      apply(compiler) {\n        compiler.hooks.compilation.tap(\"webpack-asset-relocator-loader\", compilation => {\n          relocateLoader.initAssetCache(compilation, outputAssetBase);\n        });\n      }\n    }\n  ]\n});\n```\n\n## How it Works\n\n### Asset Relocation\n\nAssets 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.\n\n* `process.cwd()`, `__filename`, `__dirname`, `path.*()`, `require.resolve` are all statically analyzed when possible.\n* File emissions for exact asset paths\n* Whole directory asset emissions for exact directory paths\n* Wildcard asset emissions for variable path expressions\n\nWhen 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.\n\n### Binary Relocation\n\nNode binary loading conventions cover the following triggers for binary relocations:\n* `require('bindings')(...)`\n* `nbind.init(..)`\n* `node-pre-gyp` include patterns\n\nAny shared libraries loaded by these binaries will also be emitted as well.\n\n### Node.js Compatibility Features\n\nIn addition to asset relocation, this loader also provides a couple\nof compatibility features for Webpack Node.js builds as part of its analysis.\n\nThese include:\n\n* `require.main === module` checks are retained for the entry point being built.\n* `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.\n* `require.resolve` support in the target environment, while also supporting emission in the build environment.\n* Dynamic `require` statements are analyzed to exact paths wherever possible, and when not possible to analyze, turned into dynamic requires in the target environment.\n","publish_time":1786586701560,"_cnpm_publish_time":1786586701560,"dist-tags":{"latest":"1.11.0"}}