{"name":"webpack-external-import","version":"0.2.3","keywords":["import url","dynamic imports url","over the wire","import() url","external url import","script injection","webpack import url","webpack","manifest"],"author":{"url":"https://github.com/ScriptedAlchemy","name":"Zack Jackson","email":"zack@ScriptedAlchemy.com"},"license":"GNU GPLv3","_id":"webpack-external-import@0.2.3","maintainers":[{"name":"zackljackson","email":"zackary.l.jackson@gmail.com"}],"homepage":"https://github.com/ScriptedAlchemy/webpack-external-import#readme","bugs":{"url":"https://github.com/ScriptedAlchemy/webpack-external-import/issues"},"dist":{"shasum":"85a087846f9f9963b88e876f8bb9ba00872689c2","tarball":"http://registry-npm.ywwl.com/webpack-external-import/download/webpack-external-import-0.2.3.tgz","fileCount":8,"integrity":"sha512-moaZ7MRunUep5ViM8A0dVoaft3UwoT4iKuyMAnSyw0ItxEbimx1OGFTGxcbtO5KwwwA4bgpBrnwoMiyWIXW7bA==","signatures":[{"sig":"MEYCIQDXz5SvP2oNw/mytYoqkWBoE/AChw2GpZ5rXOopl76KoAIhAKJdr6E9S8/eWZIYAPZlRLDyS2UdWAMDoSmErLUlkJ5U","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":94732,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdwMp2CRA9TVsSAnZWagAAzWQP/RlPWYkO5qktqBr3UX+x\ndUvmaXi1mlfPi9W+5MkAIZo9j+EdW7yxPTvzCiTZyDjrJG3nQHx3tvx25YGO\nCf2Op6NxHiaYdm5usRhkya00ogCJyQFdHe5/sqJXo8A4Vf6avdl24eFAyACb\nLZ9pTgMcj3HCqEyIZgY5PZ+SHj/ATW5eMTfL2/giQRTyZNPTOZ1H1o0MUQA8\n6TijEh5uDmtG3xa6oSpACxhZ7o1g2ihtIBjYjw5jVutRfkvJKchxdriNDWPC\nerrgM1SokJ+B+xoaOe1Q+ooigcFlRDQ/y4pRhd4ViJPNqMJu1jg18eZpa4fy\nZ451CQiNOeeSsxyRgcSmz25Yvrrv0cyiilxiNxnP0iq2328JJV1N4PRTm+WN\nzVJ9fBVnCViA3O78lxrrS1FldSPOMNPafM7y38wRA+o+SoCFamdR+8CvBgOE\nzAWc+MuXQcxiT45h1JB+XXEdDrjA+gPYrNw8j6Qd32zy3fYSqdWVlCfqPQPC\nUB8CQNxD9q7BRis+EIGEyC6FYpRFebwMe7gXmxt54clPt4pXMUJItR7YptK6\nn1ee/T/KufpfvGi91YybLht7uXv3Ce8aywGj4mrx6s+x5tLV38zLZfpugV07\n9L9j4o2J47YWVCfchmnTDioN8nfcgwSbNTaWqSrTdjqjGl6f0wlz4Yo3RLn9\nkhxq\r\n=D2Qy\r\n-----END PGP SIGNATURE-----\r\n","size":27291,"noattachment":false,"key":"/webpack-external-import/-/webpack-external-import-0.2.3.tgz"},"jest":{"preset":"jest-puppeteer"},"babel":{"plugins":["@babel/plugin-proposal-optional-chaining"],"presets":["@babel/preset-env","@babel/preset-react"]},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"gitHead":"5efc7bc7dc7aa803cc4cf72bd468481555cca928","scripts":{"demo":"yarn && yarn && yarn link webpack-external-import && concurrently \"yarn compile\" \"yarn link\" \"yarn demo:one\"  \"yarn demo:two\"","jest":"NODE_ENV=test jest","lint":"eslint --ext .js,.ts,.tsx --ignore-pattern dist,node_modules . --fix","test":"yarn  lint && yarn  tsc-test && yarn  jest","babel":"yarn compile && cd manual && yarn babel","commit":"npx git-cz","compile":"babel src -d .","jest:ci":"cross-env NODE_ENV=development jest","prepare":"yarn compile && cd manual && yarn","demo:one":"cd manual/Website1; yarn && yarn link webpack-external-import && yarn manual:dev","demo:two":"cd manual/Website2; yarn && yarn link webpack-external-import && yarn manual:dev","demo:fast":"yarn compile && yarn link && yarn demo:one:fast | yarn demo:two:fast","demo:prod":"yarn && yarn compile && yarn link && yarn demo:one:prod | yarn demo:two:prod","commitlint":"npx commitlint  --from=HEAD~1 || yarn commitlinterror","demo:debug":"npx kill-port 3200 | yarn && yarn && yarn link webpack-external-import && concurrently \"yarn compile\" \"yarn link\" \"yarn demo:one\"  \"yarn demo:two\"","demo:one:fast":"cd manual/Website1; yarn link webpack-external-import && yarn manual:dev","demo:one:prod":"cd manual/Website1; yarn && yarn link webpack-external-import && yarn manual:prod","demo:two:fast":"cd manual/Website2; yarn link webpack-external-import && yarn manual:dev","demo:two:prod":"cd manual/Website2; yarn && yarn link webpack-external-import && yarn manual:prod","commitlinterror":"echo \"$(tput setaf 1)Red text $(tput setab 7)and white background$(tput sgr 0)\"","semantic-release":"semantic-release"},"_npmUser":{"name":"zackljackson","email":"zackary.l.jackson@gmail.com"},"repository":{"url":"git+https://github.com/ScriptedAlchemy/webpack-external-import.git","type":"git"},"_npmVersion":"5.6.0","description":"dynamic import() external urls!","directories":{},"_nodeVersion":"8.10.0","dependencies":{"npm":"^6.11.3","loadjs":"^3.6.1","dimport":"^1.0.0","fs-extra":"^8.1.0","scriptjs":"^2.5.9","babel-traverse":"^6.26.0","@babel/helper-module-imports":"^7.0.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^24.9.0","react":"^16.9.0","eslint":"^6.4.0","webpack":"^4.40.2","cross-env":"^6.0.0","puppeteer":"^1.20.0","@babel/cli":"^7.6.0","babel-core":"^7.0.0-bridge.0","commitizen":"^4.0.3","prop-types":"^15.7.2","source-map":"^0.7.3","@babel/core":"^7.6.0","babel-watch":"^7.0.0","webpack-cli":"^3.3.9","babel-eslint":"^10.0.3","babel-loader":"^8.0.6","concurrently":"^4.1.2","jest-resolve":"^24.9.0","jest-haste-map":"^24.9.0","jest-puppeteer":"^4.3.0","semantic-release":"^15.13.24","@babel/preset-env":"^7.6.0","webpack-dev-server":"^3.8.1","@babel/preset-react":"^7.0.0","eslint-plugin-react":"^7.14.3","html-webpack-plugin":"^3.2.0","regenerator-runtime":"^0.13.3","eslint-config-airbnb":"^18.0.1","eslint-plugin-import":"^2.18.2","eslint-plugin-jsx-a11y":"^6.2.3","cz-conventional-changelog":"^3.0.2","@babel/plugin-transform-runtime":"^7.6.0","@typescript-eslint/eslint-plugin":"^2.3.0","@babel/plugin-transform-react-jsx":"^7.3.0","@babel/plugin-syntax-dynamic-import":"^7.2.0","@babel/plugin-proposal-class-properties":"^7.5.5","@babel/plugin-proposal-optional-chaining":"^7.6.0"},"peerDependencies":{"webpack":"^4.40.2"},"_npmOperationalInternal":{"tmp":"tmp/webpack-external-import_0.2.3_1572915829841_0.8925592349068343","host":"s3://npm-registry-packages"},"readme":"# Webpack External Import\n\n> **import() other chunks and modules from third parties, or other webpack builds themselves! At runtime!**\n\n<p align=\"center\">\n\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n  <a href=\"https://www.npmjs.com/package/webpack-external-import\">\n    <img src=\"https://img.shields.io/npm/v/webpack-external-import.svg\" alt=\"Version\" />\n  </a>\n\n  <a href=\"https://www.npmjs.com/package/webpack-external-import\">\n    <img src=\"https://img.shields.io/npm/dt/webpack-external-import.svg\" alt=\"Downloads\" />\n  </a>\n\n  <a href=\"https://www.npmjs.com/package/webpack-external-import\">\n    <img src=\"https://img.shields.io/npm/dm/webpack-external-import.svg\" alt=\"License\" />\n  </a>\n\n  <a href=\"https://www.npmjs.com/package/webpack-external-import\">\n    <img src=\"https://img.shields.io/npm/l/webpack-external-import.svg\" alt=\"License\" />\n  </a>\n</p>\n\n<p align=\"center\">\n <img src=\"docs/webpack-external-import.png\" width=\"40%\" alt=\"webpack-external-import\" />\n</p>\n\n> This project has been rewritten into the Webpack core. Its far more stable and available on npm webpack@5.0.0-beta.16 https://github.com/webpack/webpack/issues/10352\n\n> ### ⚠️ This project no longer under development as been enhanced in the webpack 5 core ⚠️\n> ### See the examples on module federation in webpack 5\n\n\\*\\*To jump to the _development_ section [click here](#development--debugging)\n\n# Installation\n\n### npm\n\n```sh\nnpm install webpack-external-import --save\n```\n\n### Yarn\n\n```sh\nyarn add webpack-external-import\n```\n\n### Version 2.0!\n\nMajor rewrite which has taken the original concept and built it directly into webpack runtime.\nA big achievement in this release is **tree-shaking support**\n\nIf you want to read me about what this tool does.\n\nRead the following:\n\n- https://link.medium.com/L5zHiwylI3\n- working on more use cases and writing about V2\n\n## Getting Started\n\n1.  Add `webpack-external-import/webpack` to your webpack plugins:\n\n```js\n// techblog.webpack.config.js\nconst URLImportPlugin = require(\"webpack-external-import/webpack\");\n{\n  plugins: [\n    new URLImportPlugin({\n      manifestName: \"website-one\"\n    })\n  ];\n}\n\n// otherblog.webpack.config\nconst URLImportPlugin = require(\"webpack-external-import/webpack\");\n{\n  plugins: [\n    new URLImportPlugin({\n      manifestName: \"website-two\"\n    })\n  ];\n}\n```\n\n2. If you are interleaving webpack bundles, load their manifests somewhere\n\n```js\n// index.js\nimport { corsImport } from \"webpack-external-import\";\nimport React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport App from \"./App.jsx\";\n\n// using Date.now() for cache busting the file. It should only less than 2kb\ncorsImport(`http://localhost:3002/importManifest.js?${Date.now()}`).then(() => {\n  ReactDOM.render(<App />, document.getElementById(\"app\"));\n});\n\n// you could also use native imports\n\nimport(\n  /* webpackIgnore:true */ `http://localhost:3002/importManifest.js?${Date.now()}`\n).then(() => {\n  ReactDOM.render(<App />, document.getElementById(\"app\"));\n});\n```\n\n## Usage\n\nThis plugin works with any Webpack driven application\n\n#### Vanilla JS\n\nThis assumes a import manifest was loaded somewhere else in the application already.\n\nIf you have not imported manifest then wrap your function in another promise:\n\n```js\ncorsImport(\"http://localhost:3002/importManifest.js\").then(() => {\n  someFunction();\n});\n```\n\nAs long as the `importManifest` was loaded - this is how it would be used\n`__webpack_require_.interleaved()` expects a module to contain both the module.id and the namespace\n\nThis allows external-import to know where to interleave from.\n`__webpack_require_.interleaved([namespace]/[module.id])`\n\nBelow is an example of interleaving a module from `website-2`\n\n```js\n// import a chunk from another website build with webpack-external-import\n\n__webpack_require__\n  .interleaved(\"website-2/ValidationRules\")\n  .then(validationRules => {\n    // proceed to use as a you would with a normal require statement\n    validationRules.validateObject(someObject);\n  });\n```\n\n### With JSX\n\n`ExternalComponent` exists for ease of use with React Components and is as SFC using React.Hooks\n\n```js\nimport { ExternalComponent } from \"webpack-external-import\";\nclass SomeComponent extends Component {\n  render() {\n    return (\n      <div>\n        <ExternalComponent\n          interleave={__webpack_require__.interleaved(\n            \"website-2/TitleComponent\"\n          )}\n          export=\"Title\"\n          title=\"Some Heading\"\n        />\n      </div>\n    );\n  }\n}\n```\n\n## What is the use of `webpack-external-import` ?\n\n- **Load components over the wire** - Pull in components at runtime.\n- **Build leaner micro-frontends (MFE)** -\n  Micro-frontends can share bundle chunks and resources with each other while remaining self-contained, removing needless code duplication.\n- **Split a large, multi-team app into separate deployable chunks while keeping it as one SPA** - Large apps can be split into separate feature bundles that can be deployed independently, reducing deployment bottlenecks.\n- **Manage common js/vendor files automatically.** - Instead of dealing with peer dependencies, externals, or anything else, you can load the dependency from a remote source.\n- **LOSA Style frontend architecture** - Run multiple apps on a single page.\n- **FOSA Style frontend orchestration** - Powerful frontend orchestration, self-organizing application architecture. Many builds act as one\n\n### Advanced Setup - Injecting Webpack modules from another build\n\nUse the webpack plugin to inject webpack modules from another build into your build.\n\n_**Important**: Make sure manifestName_ is unique per webpack build.\nIf you have multiple builds, they all need to have a unique manifestName\n\n**webpack.config.js**\n\n```js\nconst URLImportPlugin = require(\"webpack-external-import/webpack\");\n{\n  plugins: [\n    new URLImportPlugin({\n      manifestName: \"website-one\"\n    })\n  ];\n}\n```\n\n## Mark Files for interleaving\n\nPretend we have two separate apps that each have their _independent_ build. We want to share a module from one of our apps with the other.\n\nTo do this, you must add an `interleave` object to `package.json`.\nThe `interleave` object tells the plugin to make the module accessible through a predictable name.\n\nFor example:\n\n```json\n// website-two package.json\n{\n  \"name\": \"some-package-name\",\n  \"interleave\": {\n    \"src/components/Title/index.js\": \"TitleComponent\",\n    \"src/components/hello-world/index.js\": \"SomeExternalModule\"\n  }\n}\n```\n\n```js\n// website-one App.js\n__webpack_require__\n  .interleaved(\"website-3/TitleComponentWithCSSFile\")\n  .then(TitleComponentWithCSSFile => <TitleComponentWithCSSFile />);\n```\n\nThis ensures a easy way for other consumers, teams, engineers to look up what another project or team is willing\nto allow for interleaving\n\n## Working with Webpack Externals\n\nIt's important to follow the instructions below if you are planning to use Webpack externals.\nThis plugin must be installed on all builds - it is intended that the build creating providing external is built by this plugin.\nExternals work best in scenarios where the \"host\" app should supplying dependencies to an interleaved one.\n\n**Providing Externals**\nTo support webpack externals, you will need to use `provideExternals` to specify externals\n\n**Note:** you must use `provideExternals` **instead** of the webpack `externals` option.\n\n```js\nnew URLImportPlugin({\n  provideExternals: {\n    react: \"React\"\n  }\n});\n```\n\n**Consuming Externals**\nTo consume externals, you will need to use `useExternals` to inform webpack that the interleaved app should use the module specified by `provideExternals`\n\n```js\nnew URLImportPlugin({\n  useExternals: {\n    react: \"React\"\n  }\n});\n```\n\n## Full Example\n\n**WEBSITE-ONE**\n\n```js\n// app.js\n\nimport React, { Component } from \"react\";\nimport { ExternalComponent } from \"webpack-external-import\";\nimport HelloWorld from \"./components/goodbye-world\";\nimport \"react-select\";\n\nclass App extends Component {\n  constructor(props) {\n    super(props);\n    this.state = {\n      titleUrl: null,\n      manifestLoaded: false,\n      loaded: false\n    };\n  }\n\n  componentDidMount() {\n    __webpack_require__\n      .interleaved(\"website-3/TitleComponentWithCSSFile\")\n      .then(TitleComponentWithCSSFile =>\n        console.log(TitleComponentWithCSSFile)\n      );\n  }\n\n  renderDynamic = () => {\n    const { loaded } = this.state;\n    if (!loaded) return null;\n    return __webpack_require__(\"SomeExternalModule\").default();\n  };\n\n  render() {\n    return (\n      <div>\n        <HelloWorld />\n\n        <ExternalComponent\n          interleave={__webpack_require__.interleaved(\n            \"website-2/TitleComponent\"\n          )}\n          export=\"Title\"\n          module=\"TitleComponent\"\n          title=\"Some Heading\"\n        />\n\n        <ExternalComponent\n          interleave={__webpack_require__.interleaved(\n            \"website-3/TitleComponentWithCSSFile\"\n          )}\n          export=\"Title\"\n          title=\"Title Component With CSS File Import\"\n        />\n        {this.renderDynamic()}\n      </div>\n    );\n  }\n}\n\nPromise.all([\n  corsImport(`http://localhost:3002/importManifest.js?${Date.now()}`),\n  corsImport(`http://localhost:3003/importManifest.js?${Date.now()}`)\n]).then(() => {\n  ReactDOM.render(<App />, document.getElementById(\"app\"));\n});\n```\n\n**WEBSITE-TWO**\n\n```json\n// package.json\n\n{\n  \"name\": \"website-two\",\n  \"version\": \"0.0.0-development\",\n  \"author\": \"Zack Jackson <zack@ScriptedAlchemy.com> (https://github.com/ScriptedAlchemy)\",\n  \"interleave\": {\n    \"src/components/Title/index.js\": \"TitleComponentWithCSSFile\",\n    \"src/components/Title/style.css\": \"TitleComponentWithCSSFileCSS\",\n    \"src/components/hello-world/index.js\": \"SomeExternalModule\"\n  }\n}\n```\n\n## API:\n\n```js\nmodule.exports = {\n  plugins: [\n    new URLImportPlugin({\n      manifestName: \"website-one\",\n      fileName: \"importManifest.js\",\n      basePath: ``,\n      publicPath: `//localhost:3001/`,\n      writeToFileEmit: false,\n      seed: null,\n      filter: null,\n      debug: true,\n      useExternals: {},\n      provideExternals: {}\n    })\n  ]\n};\n```\n\n### `options.fileName`\n\nType: `String`<br>\nDefault: `importManifest.js`\n\nThe manifest filename in your output directory.\n\n### `options.publicPath`\n\nType: `String`\nDefault: `output.publicPath`\n\nA path prefix that will be added to values of the manifest.\n\n### `options.basePath`\n\nType: `String`\n\nA path prefix for all keys. Useful for including your output path in the manifest.\n\n### `options.writeToFileEmit`\n\nType: `Boolean`<br>\nDefault: `false`\n\nIf set to `true` will emit to build folder and memory in combination with `webpack-dev-server`\n\n### `options.seed`\n\nType: `Object`<br>\nDefault: `{}`\n\nA cache of key/value pairs to used to seed the manifest. This may include a set of [custom key/value](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json) pairs to include in your manifest or may be used to combine manifests across compilations in [multi-compiler mode](https://github.com/webpack/webpack/tree/master/examples/multi-compiler). To combine manifests, pass a shared seed object to each compiler's ManifestPlugin instance.\n\n### `options.filter`\n\nType: `Function(FileDescriptor): Boolean`\n\n### `options.testPath`\n\nType: `Function(Object, FileDescriptor): Object`<br>\nDefault: `src`\n\nTest resource path to see if plugin should apply transformations\n\n### `options.useExternals`\n\nType: `Object`<br>\nDefault: `{}`\n\nInforms the webpack treat the following dependencies as externals.\nWorks the same way externals does.\n\n### `options.provideExternals`\n\nType: `Object`<br>\nDefault: `{}`\n\nInforms webpack to provide the dependencies listed in the object to other apps using `useExternals`\n\n### **ExternalComponent**\n\nReact Component\n\n#### **Props**:\n\n**`src`: string** - a url to a javascript file, note it will need to be built by another webpack build running this plugin\n\n**`interleave`: function** - the `__webpack_require__.interleave()` function, which will return a module\n\n**`export`: string** - The named export to use as a component from the module being imported\n\n### The entry manifest\n\nEach webpack build using the webpack plugin emits a manifest file to the build output directory.\n\nThe manifest allows you to find a chunk that you want, even if the name has been hashed.\n\nBelow is an example of using the manifest.\n\nIn this file, I am importing code from another website/build. My application is loading website two's manifest, which is automatically added to `window.entryManifest` under the `manifestName` I set in the webpack plugin. After that, I'm importing a chunk from website-two, in this case - the chunk is code-split.\n\n```js\ncomponentDidMount() {\n  corsImport('http://localhost:3002/importManifest.js').then(() => {\n      const Title = __webpack_require__\n        .interleaved(\"website-two/TitleComponent\")\n\n        Title.then(console.log) // => Module {default: ()=>{}, Title: ()=>{}}\n  });\n}\n```\n\n## DEMO\n\nHow to start using the demo\nIn the _root directory_, run the following\n\n1. run `yarn install`\n2. run `yarn demo` from the root directory\n3. browse to [localhost:3001](http://localhost:3001) and you will see components from two other websites\n\nThis command will install, all dependencies, build the source for the plugin, install the demo dependencies, run all builds and start serving\n\n## Development & Debugging\n\nHow to start the demo in debug mode, using node --inspect and connecting to a chrome debugger\n\n> This is mainly for debugging the webpack plugin\n\nIn the root directory, run the following\n\n1. `yarn install`\n2. `yarn demo:debug` from the root directory\n3. browse to [localhost:3001](http://localhost:3001)\n\n**Note:** _[localhost:3001](http://localhost:3001) is the \"consumer app, while the other is the provider app\". Both apps work independently and you should check both of them out (they are extremely basic)_\n\nOpen chrome dev tools and you should see the box highlighted below appear, click on it to connect to the webpack debugger\n![GitHub Logo](/docs/inspect.png)\n\n### Logging\n\nThe default compilation removes console log statements via `babel-plugin-transform-remove-console`, which is run when `BABEL_ENV=production` (default). To compile a version with logging enabled, run `yarn compile` directly.\n","publish_time":1572915829956,"_cnpm_publish_time":1572915829956,"dist-tags":{"latest":"2.2.4","next":"3.0.0-beta.3"}}