{"name":"@vercel/webpack-asset-relocator-loader","description":"Asset relocation loader used in ncc for performing Node.js builds while emitting and relocating any asset references.","version":"1.3.1","repository":{"type":"git","url":"git+https://github.com/vercel/webpack-asset-relocator-loader.git"},"license":"MIT","main":"./dist/index.js","scripts":{"build":"ncc build src/asset-relocator.js","codecov":"codecov","test":"npm run build && jest","test-coverage":"jest --coverage --globals \"{\\\"coverage\\\":true}\" && codecov"},"devDependencies":{"@vercel/ncc":"^0.25.1","acorn":"^8.1.0","acorn-class-fields":"^1.0.0","acorn-static-class-features":"^1.0.0","bindings":"^1.4.0","codecov":"^3.6.5","estree-walker":"^0.6.1","glob":"^7.1.3","graceful-fs":"^4.1.15","jest":"^26.6.3","loader-utils":"^1.2.3","magic-string":"^0.25.1","memory-fs":"^0.4.1","node-gyp-build":"^4.2.1","node-pre-gyp":"^0.12.0","resolve":"^1.10.0","resolve-from":"3.0.0","rollup-pluginutils":"^2.8.2","semantic-release":"^17.3.0","socket.io-client":"^2.2.0","sourcemap-codec":"^1.4.4","webpack":"^4.43.0","webpack-cli":"^3.2.1"},"gitHead":"55950b592f7d83ce4e0777c5a068bb482a38ba1a","bugs":{"url":"https://github.com/vercel/webpack-asset-relocator-loader/issues"},"homepage":"https://github.com/vercel/webpack-asset-relocator-loader#readme","_id":"@vercel/webpack-asset-relocator-loader@1.3.1","_nodeVersion":"12.22.1","_npmVersion":"6.14.9","dist":{"integrity":"sha512-VJAmEd1QQ+Kh3nm/rbOz5iFeFIsSSc/SGT7iwlK3BZvyDTn5rmuwA4Up/heg4w1PDFI0qvdjxsjrlMzd37SoqQ==","shasum":"fdb4f05fd8ee37903d00f2d84b9cbd4af123aa86","tarball":"http://registry-npm.ywwl.com/@vercel/webpack-asset-relocator-loader/download/@vercel/webpack-asset-relocator-loader-1.3.1.tgz","fileCount":5,"unpackedSize":983235,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgf1JMCRA9TVsSAnZWagAAvF0P/2SSdKZGh3Bs1Q0dxejl\n8kVFCTSxSWaZwY5GOWzm3J8UoGEYGwMxaGX0NMZxxNyzhlluWUfhU4oEbRKq\nfssmfi7QCXOOW6ZQ+IVJjPGP/Zs3G0aH0JPslpFC56yKzHz3SAiIHb1d3sVY\nIFTBBwMlPu5QFAZSwIoF3Oi0xBhPY/stmsr4VeRQ+gVzCjtuMSdjaFqnRl1x\nMWW73ZbG8XmAd+/kECuriaNf/rx2iA/NZrYAIvm+rQpbPq9zYJCmIpNAWYAi\nB8tFxseWmyUJVRnYMDUdNRXNrVXlgMdeAfB6hgAgVJFM7q+SqL9tVSl392pG\nLsbRWPMTfHWnqyvpgWIvbaCutJGb9KNVITcrOvz3/P2AM0nqoNgtc34Q2qzw\n2+orZ0AUVhEsu3dSv8zUrJAjBi3nCIIFP+2fZRT9LLZHjMcJvsVp8Xm1++f7\nQhCr04F5UDjWXXQI3e6yulhDC2YW/ckwmMjc+qOte/eWinxBW399rWjc5yaM\nxMZ75kv477Q8wIYirpkpkL/uLsjDDiQ28kWY+ZL0fsuTX1HyuNY+Q+2OnhLp\nsoYqva8GGuWHOL2KTT/hwcHHYESmCylLIapIKu6/Gi/Tzw0AcczGplZ8WNSl\nmTALbFOe9fctEMDVIBe2uShCxeuKZPQThFEUrLPObUkfbvkLuYLexKQd2XP6\nfA1s\r\n=eNmI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGX6I32TMnM1pEYQQbq3WaiCR7GzmKm7dRQIux/9REG2AiEA2NrBwXwdVnznXVsqMRytEgfJ5V7OTN/rSxQdjlo9qvI="}],"size":234233,"noattachment":false,"key":"/@vercel/webpack-asset-relocator-loader/-/@vercel/webpack-asset-relocator-loader-1.3.1.tgz"},"_npmUser":{"name":"zeit-bot","email":"team@zeit.co"},"directories":{},"maintainers":[{"name":"mrmckeb","email":"mrmckeb.npm@outlook.com"},{"name":"jhoch","email":"jrshoch@gmail.com"},{"name":"ismaelrumzan","email":"ismaelrumzan@gmail.com"},{"name":"ernestd","email":"lapapelera@gmail.com"},{"name":"rizbizkits","email":"rizwana.akmal@hotmail.com"},{"name":"chriswdmr","email":"github.wolle404@gmail.com"},{"name":"coetry","email":"allenhai03@gmail.com"},{"name":"samsisle","email":"samko9522@gmail.com"},{"name":"cl3arglass","email":"haltaffer@gmail.com"},{"name":"divmain","email":"dale@divmain.com"},{"name":"raunofreiberg","email":"freiberggg@gmail.com"},{"name":"elsigh","email":"lsimon@commoner.com"},{"name":"timneutkens","email":"tim@timneutkens.nl"},{"name":"leo","email":"mindrun@icloud.com"},{"name":"chibicode","email":"shu@chibicode.com"},{"name":"ijjk","email":"jj@jjsweb.site"},{"name":"andybitz","email":"artzbitz@gmail.com"},{"name":"iamevilrabbit","email":"hello@evilrabb.it"},{"name":"joecohens","email":"joecohenr@gmail.com"},{"name":"tootallnate","email":"nathan@tootallnate.net"},{"name":"styfle","email":"steven@ceriously.com"},{"name":"zeit-bot","email":"team@zeit.co"},{"name":"quietshu","email":"ds303077135@gmail.com"},{"name":"hankvercel","email":"hank@vercel.com"},{"name":"mglagola","email":"mark.glagola@gmail.com"},{"name":"javivelasco","email":"javier.velasco86@gmail.com"},{"name":"igorklopov","email":"igor@klopov.com"},{"name":"paco","email":"pvco.coursey@gmail.com"},{"name":"dav-is","email":"mail@connordav.is"},{"name":"timer","email":"timer150@gmail.com"},{"name":"lucleray","email":"luc.leray@gmail.com"},{"name":"leerobinson","email":"lrobinson2011@gmail.com"},{"name":"matheuss","email":"matheus.frndes@gmail.com"},{"name":"nkzawa","email":"naoyuki.kanezawa@gmail.com"},{"name":"anatrajkovska","email":"ana.trajkovska2015@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/webpack-asset-relocator-loader_1.3.1_1618956875892_0.583344421042284"},"_hasShrinkwrap":false,"readme":"# Asset Relocator Loader for Webpack\n\n[![Build Status](https://circleci.com/gh/vercel/webpack-asset-relocator-loader.svg?&style=shield)](https://circleci.com/gh/vercel/workflows/webpack-asset-relocator-loader)\n[![codecov](https://codecov.io/gh/vercel/webpack-asset-relocator-loader/branch/main/graph/badge.svg)](https://codecov.io/gh/vercel/webpack-asset-relocator-loader)\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":1618956876035,"_cnpm_publish_time":1618956876035,"dist-tags":{"latest":"1.11.0"}}