{"_id":"@alexseitsinger/webpack-require-from","_rev":"2-edf5d2e07b4f8f5094bf3ac8d7485e55","name":"@alexseitsinger/webpack-require-from","dist-tags":{"latest":"1.9.1"},"versions":{"1.8.0":{"name":"@alexseitsinger/webpack-require-from","version":"1.8.0","description":"Webpack plugin that allows to configure path or URL for fetching dynamic imports","main":"index.js","scripts":{"build-webpack2":"cd ./test/webpack2 && yarn run build && cd ..","build-webpack3":"cd ./test/webpack3 && yarn run build && cd ..","build-webpack4":"cd ./test/webpack4 && yarn run build && cd ..","build-tests":"yarn run build-webpack4 && yarn run build-webpack3 && yarn run build-webpack2","test":"yarn run build-tests && yarn run test-slim","test-slim":"mocha ./test/common/*.test.js"},"peerDependencies":{"tapable":"^1.0.0"},"repository":{"type":"git","url":"https://github.com/agoldis/webpack-require-from.git"},"author":{"name":"Andrew Goldis"},"license":"MIT","devDependencies":{"lodash.clonedeep":"^4.5.0","memory-fs":"^0.4.1","mocha":"^5.2.0","tapable":"^1.0.0"},"dependencies":{"webpack-sources":"^1.4.3"},"licenseText":"MIT License\n\nCopyright (c) 2017 Andrew Goldis\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@alexseitsinger/webpack-require-from@1.8.0","dist":{"shasum":"6d8967593ec92ef7282247e7800c00067c28caca","integrity":"sha512-W5RmW+5quINMadaJijoVAmAdaHexwPcFkKnn2mMwzmZeJ2C4Bs8b0Pi1pGeXpj51zb/c17jYoZgadLfBmbkP9w==","tarball":"https://registry.npmjs.org/@alexseitsinger/webpack-require-from/-/webpack-require-from-1.8.0.tgz","fileCount":43,"unpackedSize":57069,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd1IVgCRA9TVsSAnZWagAAlIsQAJcXIvffHexJCTC7kbSD\nD23/p6izWrvLsSvErVLFOpsCFOVHbjkBqf0CX/cSdUKBHx6+8LXU/T/C9/wj\nRgNEWs85OvElM0t1QtCcMmKSzjd12POnn/WmV6L65GU0V9IDT5+dCL8as8as\nm7nqPkY0t9m6+7mT70154+EUDE8pDZ0KPPWPx7Uxy1uQXFX0OfvzzgcamSRb\noS+xmZb6WMGsjquweoDGcVr94ycmzx+SJsIU7MLg783cGRoeLRzKVJNRdMu4\nJYG+2mSElKWF4Jvw9Nsn/5RRrlr6ZdGdQFOyaSNsP+jJ4HPKBQl/cfjFR1HX\nNpKAtlq37B5mLGxix5CwZi2YuzN4XrdsVeUWx1AfgHMgzB5lHYja2oVjhlwC\nDDWGIxsPjZf+HCHFFBOtuI/usA4Yj4NIdpDat5zlSo2ZPFYvDTyGYB6wDbTl\nSb9qzsghBP7HlTGLbY8N9shDDiHkfjY55zuz+2QqW7lgTnLqYpaB2GTI1+gR\nQ7d8EMGIlXK4yaedID8/Rbkq3R5w4z0gMAY4ef611UlB7MODh6/1Ij66KzaC\nk94bggPrm+gBYbP4wOLByDtLvaLtw5RC1K4FEeTMXdHJ7Ph10rT5lhBH1yGX\nfdbWVAihckwNUavjkq5d84V/yXTj+Ndgj6KP8FuSin6SLc3MPezVTdjzPyUD\nD0Ti\r\n=e+zk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG3tfjkrq1DUCLGuIN3G+4Ijy9ihjbqMcmHzWRX0+dm9AiB0HjRYAKdmgV61Sf6i+cRdd4MpD1kwCCKe/QV3ZXlPPw=="}]},"maintainers":[{"name":"alexseitsinger","email":"alexseitsinger@gmail.com"}],"_npmUser":{"name":"alexseitsinger","email":"alexseitsinger@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/webpack-require-from_1.8.0_1574208864159_0.5895991797482973"},"_hasShrinkwrap":false},"1.9.1":{"name":"@alexseitsinger/webpack-require-from","version":"1.9.1","description":"Webpack plugin that allows to configure path or URL for fetching dynamic imports","main":"index.js","scripts":{"build-webpack2":"cd ./test/webpack2 && yarn run build && cd ..","build-webpack3":"cd ./test/webpack3 && yarn run build && cd ..","build-webpack4":"cd ./test/webpack4 && yarn run build && cd ..","build-tests":"yarn run build-webpack4 && yarn run build-webpack3 && yarn run build-webpack2","test":"yarn run build-tests && yarn run test-slim","test-slim":"mocha ./test/common/*.test.js"},"peerDependencies":{"tapable":"^1.0.0"},"repository":{"type":"git","url":"https://github.com/agoldis/webpack-require-from.git"},"author":{"name":"Andrew Goldis"},"license":"MIT","devDependencies":{"lodash.clonedeep":"^4.5.0","memory-fs":"^0.4.1","mocha":"^5.2.0","tapable":"^1.0.0"},"dependencies":{"webpack-sources":"^1.4.3"},"licenseText":"MIT License\n\nCopyright (c) 2017 Andrew Goldis\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@alexseitsinger/webpack-require-from@1.9.1","dist":{"shasum":"bcadb35e85133b0f8c133913bcab56e4c101e0c3","integrity":"sha512-FNAj2qQRMIHSDFc61o7EbhhQES1IYx1rAMbjwwyBj+GulC879lDadn3fadYq+2e8UPWOSa+Z0Nm23lIcJT4coA==","tarball":"https://registry.npmjs.org/@alexseitsinger/webpack-require-from/-/webpack-require-from-1.9.1.tgz","fileCount":43,"unpackedSize":57531,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd1mltCRA9TVsSAnZWagAA74wP/i8ylHww+BtYBHYvHMn3\nPNqmQyb54wya7khfSDCEC3QxZasovPAPVetFzaWIM9KIUVoglxj6bs15Tlts\nulDWTi5sSAe9KWBp80IvUSCiWGMGabPJUP7KGfHdUCmnmNxrYAQu+uYjyfLq\nX+qaXM9PwKqFjkNbG7p2DkvOWfnpn3i0T3/cgXjKE81YuqnpJNJuazQhpkVT\nEGC8Vn5/fJPMBTmKFURVlmBzEDB9hqwxwXS+7B8Idss/SLhgZCNqRhU5T8SQ\nTJmV10o6JJIeFo6frye9KpFt364xNADVrPvuyc7/FIcu1CmFVDFdxhWMuhe/\nIxvmyE9wj/PsQFzlaNUQVR9bIHH2BP4zxrbqUVPWBTb2HU/pJGpk6EeWywNm\nUfGAlv+I5/B1c7luXdF9odWta8SCRlz0wDueGGfTkphcCVaNgAlWDMpMoJiA\nk4dRlcksT+FLzBlXdAGsOQfPoHQr1PEBzpK0vuY9KpcJgfndcW7c2DvfG5Ve\noVXgIVtwOEOUPkQDaJCAy0SZ8txPdi3GAf8XivEycHc+YiijvUYt7AVc5TSt\na9WhGvLVv7wf0rZx3YnjjzsEXTfeqjKD/wEB7XlgEGvl+EXoNUNxN6++Ulf2\nUr79LGyxMGhZF260EsqgO8ROk9F6yvbmMyujPbpXNTwogUpN4D2OFzZ+OEsf\nYAJs\r\n=BdHB\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH+ULTeyPI5ZcLzA22exUDXMu5Wfi8+0jA3zBa35spTJAiEA+fu1sgZvCpiTvGu9Jxu+gfaoFyr7v4k1C8rIYhhLGng="}]},"maintainers":[{"name":"alexseitsinger","email":"alexseitsinger@gmail.com"}],"_npmUser":{"name":"alexseitsinger","email":"alexseitsinger@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/webpack-require-from_1.9.1_1574332780508_0.2164918747627338"},"_hasShrinkwrap":false}},"time":{"created":"2019-11-20T00:14:23.924Z","1.8.0":"2019-11-20T00:14:24.307Z","modified":"2022-04-04T12:41:43.118Z","1.9.1":"2019-11-21T10:39:40.679Z"},"maintainers":[{"name":"alexseitsinger","email":"alexseitsinger@gmail.com"}],"description":"Webpack plugin that allows to configure path or URL for fetching dynamic imports","repository":{"type":"git","url":"https://github.com/agoldis/webpack-require-from.git"},"author":{"name":"Andrew Goldis"},"license":"MIT","readme":"[![npm version](https://badge.fury.io/js/webpack-require-from.svg)](https://badge.fury.io/js/webpack-require-from)\n[![npm](https://img.shields.io/npm/dm/webpack-require-from.svg)](https://www.npmjs.com/package/webpack-require-from)\n[![CircleCI](https://circleci.com/gh/agoldis/webpack-require-from.svg?style=svg)](https://circleci.com/gh/agoldis/webpack-require-from)\n\n# webpack-require-from\n\nWebpack plugin that allows to configure the path / URL for fetching dynamic imports\n\n- Compatible with webpack 4, 3, 2\n- Supports web-workers loading (https://github.com/webpack-contrib/worker-loader)\n- Lightweight\n- No dependencies\n- Tested\n- Production-ready\n\n# Why is it helpful?\n\nWebpack allows to atomatically split and load code using [`require.ensure`](https://webpack.js.org/api/module-methods/#require-ensure) or [dynamic import](https://webpack.js.org/guides/code-splitting/#dynamic-imports) `import()`. Those modules are fetched on-demand when your main bundle is running is browser.\n\nWebpack loads the modules (chunks) from a static URL, which is determined by `config.output.publicPath` of [webpack configuration](https://webpack.js.org/guides/public-path/#on-the-fly).\n\nSometimes you need to change this URL for loading modules (chunks), when, for example:\n\n- Chunks are hosted at a CDN\n- Different environments use different URLs for loading assets (production, staging, qa)\n- Your `index` file is served from a different location / port\n- You need to dynamically load pre-compiled files from a different location\n- You need to load 3rd part web worker from a CDN\n\n# How to use\n\n```javascript\n// webpack.config.js\nconst WebpackRequireFrom = require(\"webpack-require-from\");\nconst webpackRequireFromConfig = (module.exports = {\n  output: {\n    publicPath: \"/webpack/\"\n  },\n  plugins: [\n    new WebpackRequireFrom({\n      // see configuration options below\n    })\n  ]\n});\n```\n\n# Configuration\n\nIf no options provided, the plugin will use the default [`config.output.publicPath`](https://webpack.js.org/guides/public-path/#on-the-fly). Check out the \"example\" directory.\n\n## `path`\n\nSet path for dynamically loading modules. The value you provide will replace `config.output.publicPath` when dynamically importing chunks.\n\nFor example, if default URL is `https://localhost`, chunk name is `0.js` and options object is `{path: \"customPath/\" }`, the chunk will be fetched from `https://localhost/customPath/0.js`\n\n> **NOTE** `path`, `methodName` and `variableName` are mutualy exclusive and cannot be used together\n\n## `variableName`\n\n`variableName` is the globaly defined variable that will be evaluated at runtime, `variableName` is the name of a variable with string value that represents a path / URL that will be used for dynamically importing of chunks.\n\nFor example, if default URL is `https://localhost`, chunk name is `0.js` and options object is `{variableName: \"chunkURL\" }`, while `window.chunkURL` is defined to be:\n\n```javascript\nwindow.chunkURL = \"https://app.cdn.com/buildXXX/\";\n```\n\nthe chunk will be fetched from `https://app.cdn.com/buildXXX/0.js`\n\n## `methodName`\n\nName of the globaly defined method that will be invoked at runtime, the method should return a path / URL that will be used for dynamically importing of chunks.\n\nFor example, if default URL is `https://localhost`, chunk name is `0.js` and options object is `{methodName: \"getChunkURL\" }`, while `window.getChunkURL` is defined to be:\n\n```javascript\nwindow.getChunkURL = function() {\n  if (true) {\n    // use any condition to choose the URL\n    return \"https://app.cdn.com/buildXXX/\";\n  }\n};\n```\n\nthe chunk will be fetched from `https://app.cdn.com/buildXXX/0.js`\n\nIf used together with `replaceSrcMethodName`, chunks URL will be first modified by `window[methodName]` and then, the modified values are passed as an argument to `window[replaceSrcMethodName]` function.\n\n> **NOTE** `path`, `methodName` and `variableName` are mutualy exclusive and cannot be used together\n\n> **NOTE** that the method should be defined in a global namespace and should be defined before `require.ensure` or `import()` is invoked. See examples below\n\n## `replaceSrcMethodName`\n\nName of the globaly defined method that will be invoked at runtime; the method receives the **full URL** of the dynamically required chunk as its argument and should return a `string` with the new URL.\n\nFor example, if default URL is `https://localhost`, chunk names are `0.js` and `common.js`, options object is `{replaceSrcMethodName: \"replaceSrc\" }`, while `window.replaceSrc` is defined to be:\n\n```javascript\nwindow.replaceSrc = function(originalSrc) {\n  if (originalSrc.match(/common/)) {\n    // rename specific chunk\n    return originalSrc.replace(/common/, \"static\");\n  }\n  return originalSrc;\n};\n```\n\nthe chunks will be fetched from `https://localhost/0.js` and `https://localhost/static.js`\n\nIf used together with `methodName` or `variableName`, chunks URL will be first modified by `window[methodName]` or will be modified to `window[variableName]` and then, the modified values are passed as an argument to `window[replaceSrcMethodName]` function.\n\n> **NOTE** that the method should be defined in a global namespace and should be defined before `require.ensure` or `import()` is invoked.\n\n## `suppressErrors (default: false)`\n\nThe plugin will invoke `console.error` when the method name you defined in `replaceSrcMethodName`, `methodName` or `variableName` cannot be detected. Turning this option on will suppress the error messages.\n\n## Defining gobaly available methods and variable\n\nWhen your JS code is executed in browser, the variable/methods whose names you mention as `variableName`, `methodName` or `replaceSrcMethodName` value, should be set **before** the first call to `require.ensure()` or `import()` is executed.\n\nThe return value of the methods will be used to build the URL for fetching resources.\n\nFor example, let's define `veryFirst` method to be globally available before you main bundle is being executed.\n\nAdd the method definition at the very first line of you bundle:\n\n```javascript\nconst window.veryFirst = function () {\n console.log(\"I am very first!\");\n}\n```\n\nYou can use a separate file and use `webpack`'s [entry point list](https://webpack.js.org/configuration/entry-context/#entry):\n\n```javascript\n// filename: veryFirst.js\nconst window.veryFirst = function () {\n console.log(\"I am very first!\");\n}\n\n// file webpack.config.js\nmodule.exports = {\n  entry: {\n    ['./veryFirst.js', './index.js']\n  }\n}\n```\n\nAnother approach is to define `veryFirst` as part of `index.html` when building it on your server:\n\n```javascript\n// filename: server/app.js\napp.get(\"/\", (req, res) =>\n  res.render(\"views/index\", {\n    cdnPath: \"https://qa.cdn.com/|https://prod.cdn.com/\"\n  })\n);\n```\n\n```HTML\n<!-- filename: views/index.ejs -->\n<html>\n<script>\n  const baseCDN = \"<%= cdnPath %>\";\n  window.veryFirst = function () {\n      console.log(`${baseCDN}/js/`);\n  }\n</script>\n...\n</html>\n```\n\n# Web Worker\n\n**TL;DR**\n\nUse [`replaceSrcMethodName`](#replacesrcmethodname) to provide a method for modifying web-worker loading path. The method must be globally available and defined before `import()` calls within your web-worker. From `example` directory:\n\n```javascript\n/* webpack.config.js */\n  // ...\n  module: {\n    rules: [\n      {\n        test: /worker\\.js$/,\n        use: {\n          loader: `worker-loader`\n        }\n      }\n    ]\n  },\n  plugins: [\n    new HtmlWebpackPlugin(),\n    new RequireFrom({\n      replaceSrcMethodName: \"getSrc\"\n    })\n  ]\n  // ...\n\n\n/* worker.js */\nrequire(\"./globals.js\");\n\nimport(\"./worker-module.js\").then(workerModule => {\n  workerModule.default();\n  console.log(\"loaded workerModule\");\n});\n\n```\n\n**Details**\n\nThe plugin allows to change the loading path of web-workers.\n\nDo to so, use the [`worker-loader`](https://github.com/webpack-contrib/worker-loader) loader. The loader uses [`importScripts`](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts) to dynamically load modules from within your web-worker and support [cross-domain web workers](https://benohead.com/cross-domain-cross-browser-web-workers/). More specifically it:\n\n1.  Creates a new webpack entry that only contains `new Worker(workerURL)`, while `workerURL` is your main webworker module\n2.  Enhances your webworker main module with webpack runtime utilities\n3.  Uses `importScripts` to dynamically load new modules within webworker context (thus avoiding cross-domain limitations)\n\nThe plugin monkey-patches `importScripts` and invokes the method you've defined within [`replaceSrcMethodName`](#replacesrcmethodname) configuration option. The method you've provided will be invoked just before calling `importScripts` with the required module path as the single argument.\n\nCheck out the working example of using the plugin with web-workers at [web2fs-notepad](https://github.com/sushain97/web2fs-notepad/commit/06b3ece074f1c1c96d9bb75436181147943f6026#diff-028b78cada5fa9a59260b989f3b86ffeR52) by @sushain97.\n\n# Troubleshooting\n\n> `${methodName} is not a function or not available at runtime.`\n\n- Make sure your method name in `webpack.config.js` matches the method name you define on global `window` object.\n\n- Make sure the method is defined **before** the very first invocation of either `require.ensure()` or `import()`\n\n  > `Specify either \"methodName\" or \"path\", not together.`\n\n- `path` and `methodName` are mutualy exclusive and cannot be used together, use either of them\n\n> `'${methodName}' does not return string.`\n\n- when using `replaceSrcMethodName` options the result of invoking `window[replaceSrcMethodName]` is validated - it\n  should be defined and be a string\n\n- make sure you return a string value from `window[replaceSrcMethodName]`\n\nDon't hesitate to open issues.\n\n# Tests\n\n`yarn test`\n","readmeFilename":"README.md"}