{"_id":"webpack-alternate-require-loader","_rev":"81-7f439d4fa577c22954c3e3673d7bf565","name":"webpack-alternate-require-loader","dist-tags":{"latest":"0.0.3"},"versions":{"0.0.1":{"name":"webpack-alternate-require-loader","version":"0.0.1","keywords":["webpack","builder","require"],"author":{"name":"Ryan Roemer","email":"ryan.roemer@formidablelabs.com"},"license":"MIT","_id":"webpack-alternate-require-loader@0.0.1","maintainers":[{"name":"ryan.roemer","email":"ryan@loose-bits.com"}],"homepage":"https://github.com/FormidableLabs/webpack-alternate-require-loader#readme","bugs":{"url":"https://github.com/FormidableLabs/webpack-alternate-require-loader/issues"},"dist":{"shasum":"cad613e9558ebaf53e9ba889161da1e9714fc8d1","tarball":"https://registry.npmjs.org/webpack-alternate-require-loader/-/webpack-alternate-require-loader-0.0.1.tgz","integrity":"sha512-oD6P8gZYY4/YcHwKZJtkari7WYuJzuSZwvqrw2NJ4sNdu7NGX8Q6FtK7gb7yvMTcl82paLd3C3CbVgXPBx7hzQ==","signatures":[{"sig":"MEQCIGZoqbIllFsMCTwiJ0/M+uykXRxEcx/TZkrwr/8J8NWPAiA0ZU2qxjHyLPICBTDXS9ba0xYCK3YSRI0+fcuFnZuMPw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"lib/index.js","_from":".","_shasum":"cad613e9558ebaf53e9ba889161da1e9714fc8d1","gitHead":"134c369311f6be004fe07bab4ce1692e374d9e7d","scripts":{"lint":"eslint lib demo/*.js demo/nested","test":"bash test/verify-builds.sh","check":"npm run lint && npm run test","clean":"rimraf demo/build*","build-demo-wp":"npm run clean && cd demo && webpack"},"_npmUser":{"name":"ryan.roemer","email":"ryan@loose-bits.com"},"repository":{"url":"git+https://github.com/FormidableLabs/webpack-alternate-require-loader.git","type":"git"},"_npmVersion":"3.10.9","description":"Webpack alternate require loader","directories":{},"_nodeVersion":"4.3.2","dependencies":{"loader-utils":"^0.2.16"},"devDependencies":{"eslint":"^2.13.1","rimraf":"^2.5.4","webpack":"^1.13.3","eslint-plugin-import":"^1.16.0","eslint-plugin-filenames":"^1.1.0","eslint-config-formidable":"^2.0.1"},"_npmOperationalInternal":{"tmp":"tmp/webpack-alternate-require-loader-0.0.1.tgz_1479767602137_0.3380982798989862","host":"packages-18-east.internal.npmjs.com"}},"0.0.2":{"name":"webpack-alternate-require-loader","version":"0.0.2","keywords":["webpack","builder","require"],"author":{"name":"Ryan Roemer","email":"ryan.roemer@formidablelabs.com"},"license":"MIT","_id":"webpack-alternate-require-loader@0.0.2","maintainers":[{"name":"ryan.roemer","email":"ryan@loose-bits.com"}],"homepage":"https://github.com/FormidableLabs/webpack-alternate-require-loader#readme","bugs":{"url":"https://github.com/FormidableLabs/webpack-alternate-require-loader/issues"},"dist":{"shasum":"bbbb905a030eee6c5869c56dc7af1d919fd38fde","tarball":"https://registry.npmjs.org/webpack-alternate-require-loader/-/webpack-alternate-require-loader-0.0.2.tgz","integrity":"sha512-b3poXQASjY/W9EtkSXtqFFuMwzsoXwHysMYlLBgpkEFavm4/I1H5zEhATUkBb79V8V6mjHnIlLqYZJ6H4YagfQ==","signatures":[{"sig":"MEUCIQCd2QHT1nuwPHd9BNXl/CwKI/6UxnLtgmgUebpdgLSkJAIgXTkRXD8K3GE5FVMP25D28p9AlfhGAQcmuU+DJ2oCrUM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"lib/index.js","_from":".","_shasum":"bbbb905a030eee6c5869c56dc7af1d919fd38fde","gitHead":"b267547acb87e918264070ac685e09c7ec98c19c","scripts":{"lint":"eslint lib demo/*.js demo/nested","test":"bash test/verify-builds.sh","check":"npm run lint && npm run test","clean":"rimraf demo/build*","build-demo-wp":"npm run clean && cd demo && webpack"},"_npmUser":{"name":"ryan.roemer","email":"ryan@loose-bits.com"},"repository":{"url":"git+https://github.com/FormidableLabs/webpack-alternate-require-loader.git","type":"git"},"_npmVersion":"3.10.9","description":"Webpack alternate require loader","directories":{},"_nodeVersion":"4.3.2","dependencies":{"loader-utils":"^0.2.16"},"devDependencies":{"eslint":"^2.13.1","rimraf":"^2.5.4","webpack":"^1.13.3","webpack-fail-plugin":"^1.0.5","eslint-plugin-import":"^1.16.0","eslint-plugin-filenames":"^1.1.0","eslint-config-formidable":"^2.0.1"},"_npmOperationalInternal":{"tmp":"tmp/webpack-alternate-require-loader-0.0.2.tgz_1479768225893_0.7749137762002647","host":"packages-12-west.internal.npmjs.com"}},"0.0.3":{"name":"webpack-alternate-require-loader","version":"0.0.3","keywords":["webpack","builder","require"],"author":{"name":"Ryan Roemer","email":"ryan.roemer@formidablelabs.com"},"license":"MIT","_id":"webpack-alternate-require-loader@0.0.3","maintainers":[{"name":"ryan.roemer","email":"ryan@loose-bits.com"}],"homepage":"https://github.com/FormidableLabs/webpack-alternate-require-loader#readme","bugs":{"url":"https://github.com/FormidableLabs/webpack-alternate-require-loader/issues"},"dist":{"shasum":"991f4e827bdd7ace6a5487317bce61ca218bb3f4","tarball":"https://registry.npmjs.org/webpack-alternate-require-loader/-/webpack-alternate-require-loader-0.0.3.tgz","integrity":"sha512-pt11wkcqvoRn7gFlYvSi/KJPzf4YSebmHEr3oSs5178jSFNLWmr19XGeTEuM2WVbnAyL+x3R1lQzB562BCWzfw==","signatures":[{"sig":"MEUCIGF8LBB8qJakm6e0NwSLfJ1OUtnIa0rIC1wxrx2W2q9SAiEA3K/AMSr1jKxBr9vcj1qlowoMX2FSFK27J1Q405no7HU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"lib/index.js","_from":".","_shasum":"991f4e827bdd7ace6a5487317bce61ca218bb3f4","gitHead":"2c7b3a668fcd5a92d302ea41146f0605529baafa","scripts":{"lint":"eslint lib demo/*.js demo/nested","test":"bash test/verify-builds.sh","check":"npm run lint && npm run test","clean":"rimraf demo/build*","build-demo-wp":"npm run clean && cd demo && webpack"},"_npmUser":{"name":"ryan.roemer","email":"ryan@loose-bits.com"},"repository":{"url":"git+https://github.com/FormidableLabs/webpack-alternate-require-loader.git","type":"git"},"_npmVersion":"2.15.11","description":"Webpack alternate require loader","directories":{},"_nodeVersion":"4.6.2","dependencies":{"loader-utils":"^0.2.16"},"devDependencies":{"eslint":"^2.13.1","rimraf":"^2.5.4","webpack":"^1.13.3","webpack-fail-plugin":"^1.0.5","eslint-plugin-import":"^1.16.0","eslint-plugin-filenames":"^1.1.0","eslint-config-formidable":"^2.0.1"},"_npmOperationalInternal":{"tmp":"tmp/webpack-alternate-require-loader-0.0.3.tgz_1491475633709_0.48142166645266116","host":"packages-18-east.internal.npmjs.com"}}},"time":{"created":"2016-11-21T22:33:24.188Z","modified":"2026-07-20T21:17:18.935Z","0.0.1":"2016-11-21T22:33:24.188Z","0.0.2":"2016-11-21T22:43:46.132Z","0.0.3":"2017-04-06T10:47:15.654Z"},"bugs":{"url":"https://github.com/FormidableLabs/webpack-alternate-require-loader/issues"},"author":{"name":"Ryan Roemer","email":"ryan.roemer@formidablelabs.com"},"license":"MIT","homepage":"https://github.com/FormidableLabs/webpack-alternate-require-loader#readme","keywords":["webpack","builder","require"],"repository":{"url":"git+https://github.com/FormidableLabs/webpack-alternate-require-loader.git","type":"git"},"description":"Webpack alternate require loader","maintainers":[{"email":"sarahmichelleegan@gmail.com","name":"sarmeyer"},{"email":"mariano.martinez@formidable.com","name":"mariano-formidable"},{"email":"ryan@loose-bits.com","name":"ryan.roemer"},{"email":"admin@formidablelabs.com","name":"formidable-owner"},{"email":"npm@formidablelabs.com","name":"formidablelabs"},{"email":"sarah.wright@formidable.com","name":"sarahformidable"},{"email":"senesealessandro@gmail.com","name":"ceceppa"}],"readme":"Webpack Alternate Require Loader\n================================\n\n[![Build Status][trav_img]][trav_site]\n\nThis loader allows webpack to approximate arcane Node.js `require` semantics for\nadvanced use cases when a normal `require` doesn't suffice\n\n## Background\n\n*The Problem*\n\nLet's say you have a project like:\n\n```\nsrc/index.js\nsrc/outside-of-resolution-path/node_modules/foo\n```\n\nif you\ntry:\n\n```js\n// src/index.js\n// BAD: Fails\nvar foo = require(\"foo\");\n```\n\nThis will fail, because `src/outside-of-resolution-path/node_modules` is not in\nthe resolution path, which is:\n\n```\nsrc/node_modules\nnode_modules\n```\n\n*The Module Pattern*\n\nOne solution to this problem is called the \"[module pattern][]\", which adds\nan extra file to start Node.js module resolution from a _different_ directory.\nBasically, say we add a simple file in a directory _outside_ of the current\nNode.js `require` resolution path:\n\n```js\n// src/outside-of-resolution-path/require.js\n// Re-export the `require` to start resolution from `src/outside-of-resolution-path/node_modules`\nmodule.exports = require;\n```\n\nAnd switched our importing code to:\n\n```js\n// src/index.js\n// GOOD: Module pattern (re-exported `require`) works!\nvar foo = require(\"./outside-of-resolution-path/require\")(\"foo\");\n```\n\nthis _works_ because the Node.js resolution path starts from the re-exported\n`require`:\n\n```\nsrc/outside-of-resolution-path/node_modules\nsrc/node_modules\nnode_modules\n```\n\n*Webpack*\n\nThe above pattern works just fine for Node.js. Unfortunately, this non-standard\n`require` usage fails in Webpack.\n\n_Enter this loader_, which allows a bridge for webpack builds to also use the\nmodule pattern / other non-standard requires.\n\n## Installation\n\nThe loader is available via [npm](https://www.npmjs.com/package/webpack-alternate-require-loader):\n\n```sh\n$ npm install --save webpack-alternate-require-loader\n```\n\n## Usage\n\nThe plugin takes a configuration object of a re-exported module path to search\nfor in code and then a resolved path to that same code on disk like:\n\n```js\n{\n  \"CODE_TO_MATCH\": require.resolve(\"REEXPORTED_CODE_PATH\")\n  \"./outside-of-resolution-path/require\": require.resolve(\"./outside-of-resolution-path/require\")\n}\n```\n\nIt will then effectively transform something like:\n\n```js\nvar foo = require(\"CODE_TO_MATCH\")(\"foo\");\nvar foo = require(\"./outside-of-resolution-path/require\")(\"foo\");\n```\n\nto:\n\n```js\nvar foo = require(\"/RESOLVED/PATH/TO/foo\");\n```\n\nThis effectively simulates what Node.js would do at execution time to the code.\n\n## Examples\n\nA basic configuration:\n\n```js\nmodule.exports = {\n  module: {\n    loaders: [\n      {\n        test: /\\.js$/,\n        loader: \"webpack-alternate-require-loader\",\n        query: JSON.stringify({\n          \"./outside-of-resolution-path/require\": require.resolve(\"./outside-of-resolution-path/require\")\n        })\n      }\n    ]\n  }\n};\n```\n\nAdditional examples are provided in:\n[`demo/webpack.config.js`](demo/webpack.config.js). If you have a clone of this\nrepository with `devDependencies`, you can run:\n\n```sh\n$ npm run build-demo-wp\n```\n\nand see the results in the [`demo`](demo) directory.\n\n## Notes\n\n**Do I have to use _exactly_ the module / require pattern above?**\n\nYes. Although Node.js can figure out:\n\n```js\nvar altRequire = require(\"./outside-of-resolution-path/require\");\nvar foo = altRequire(\"foo\");\n```\n\nThis plugin currently cannot because it is naive and uses regexes. You _must_\nfollow the form:\n\n```js\nvar foo = require(\"./outside-of-resolution-path/require\")(\"foo\");\n```\n\nFortunately, if you are using\n[`babel-plugin-replace-require`](https://github.com/FormidableLabs/babel-plugin-replace-require),\nyou can easily produce `require` expressions that work with this plugin.\n\n**Why can't I just prepend the non-standard `node_modules` path in code?**\n\nSee the [module pattern][] discussion page. Basically, with top-level\ndependencies you _can_. But with nested dependencies and modern `npm` / `yarn`\nthe real depended on code can be located anywhere in the tree. And you need\nthe `node_modules` search path to be different than normal.\n\n**You're using regexes? Yuck!**\n\nIndeed. But that's basically how webpack / some loaders roll. We stick to an\neasy pattern and avoid the cost of a full babel install + parsing. But, we may\nbe open to _real_ code parsing in the future.\n\n## Contributions\n\nContributions welcome! Make sure to pass `$ npm run check`.\n\n[trav]: https://travis-ci.org/\n[trav_img]: https://api.travis-ci.org/FormidableLabs/webpack-alternate-require-loader.svg\n[trav_site]: https://travis-ci.org/FormidableLabs/webpack-alternate-require-loader\n[module pattern]: https://github.com/FormidableLabs/builder#node-require-resolution-and-module-pattern\n","readmeFilename":"README.md"}