{"name":"webpack-external-import","version":"2.0.0","keywords":["import url","dynamic imports url","over the wire","import() url","external url import","script injection","webpack import url","webpack","manifest","dynamic dll plugin","dll plugin","runtime"],"author":{"url":"https://github.com/ScriptedAlchemy","name":"Zack Jackson","email":"zack@ScriptedAlchemy.com"},"license":"GPL-3.0-only","_id":"webpack-external-import@2.0.0","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":"dcc98ef2f6609fdee8f88564bf9e76fa32f9e593","tarball":"http://registry-npm.ywwl.com/webpack-external-import/download/webpack-external-import-2.0.0.tgz","fileCount":15,"integrity":"sha512-HPqXA1Hqo6uOdS27J0Nz+8JRCvGouPjG5sGJ0Tp7AAPc+LucaX1/JkRJRoFtbDZfFteT2EVU0csLfSptIi+5eA==","signatures":[{"sig":"MEQCIEOR+17Ftni8QSqfGnQDgjw/A+JWqBERoVVC8xEIxvMIAiBI50v5KRlY7/m3y0qvxOaQqXdC9LZPkcT8jbSbb3I53w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":124974,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeMRJeCRA9TVsSAnZWagAAK9EP/RRqAvy6U0EAfHM2KVVX\nMGv+WoIcn5FFMVarQZetCUI/ezW2ZOIZ8BBDaG6FDFpBixcgziDlRMZYcp7L\ne6WiP4z1oG9xL/y8XZ/dA4M+FWDMEig7mzQgvky3g3YGfmWM3bXK1PT9zfr4\nKIUnaGFToAzpcarPbiaTZbkYS5T+SWySaSlMmJeXwJkXXRcPkx6tA0Y52zpr\nxqPNo4fIZr6nui2am2X+Tjkigi3iCANcUMbkGUEvNLSFAWtgiDWlmnL1sCKJ\nvKiYucjR3QUgCrtsbRdsX9hrVjyFu7jSMnR7MOxih3q/zXsH98JUweQbx82q\nbE6K7rBFscLNyaaPxa75aVrdGu9hBDaDU4uU4VptcW6X4BrQxXJTPfO2u8Z7\n9yRmDkYMnqd6K3XnmRNSU62FmHiWZnfJnmkvaeBR8YT2hoicXPuAbKIQC2hb\nocbCGz5JRJnxDC5Z1gIBlMS81ToFocQ87XnQy9UW5FhyCreZY4meHuLjOcbb\nVMvHni0yla3QWlYrogWX6RuE3PEBbcgbs++QCx3EczND2sMO8w6+rA8F6Ft9\nogI6QT7NGdi0K2yRjGipg01+0gzX+df6f9FBHyixn6gbOf/RthJu1gej9p3f\nJK4X8F5Or7vJAXNE5K851st9p+qdmnmZZoVQttfZmvY73nciPECIVjD8CfU1\ni6et\r\n=ZhWr\r\n-----END PGP SIGNATURE-----\r\n","size":35008,"noattachment":false,"key":"/webpack-external-import/-/webpack-external-import-2.0.0.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":"f33e31400400baaf41a80d9dbc97bd459a236d66","scripts":{"demo":"yarn && yarn link webpack-external-import && concurrently \"yarn compile\" \"yarn link\" \"yarn demo:one\"  \"yarn demo:two\"  \"yarn demo:three\"","jest":"NODE_ENV=test jest","lint":"eslint --ext .js,.ts,.tsx src --fix","test":"yarn  lint","babel":"yarn compile && cd manual && yarn babel","commit":"npx git-cz","compile":"babel src -d .","decrypt":"node decrypt.js","encrypt":"node encrypt.js","jest:ci":"cross-env NODE_ENV=development jest","prepare":"yarn compile && cd manual && yarn","demo:one":"cd manual; yarn && cd 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","demo:debug":"yarn && yarn link webpack-external-import && concurrently \"yarn kill-ports\" \"yarn compile\" \"yarn link\" \"yarn demo:one\" \"yarn demo:two\" \"yarn demo:three:debug\"","demo:three":"cd manual/Website3; yarn && yarn link \"webpack-external-import\" && yarn manual:dev","kill-ports":"lsof -ti:3001 | xargs kill -9; lsof -ti:3002 | xargs kill -9; lsof -ti:3003 | xargs kill -9","demo:one:prod":"cd manual/Website1; yarn && yarn link \"webpack-external-import\" && yarn manual:prod","demo:two:prod":"cd manual/Website2; yarn && yarn link \"webpack-external-import\" && yarn manual:prod","demo:two:debug":"cd manual/Website2; yarn && yarn link \"webpack-external-import\" && yarn manual:debug","demo:three:prod":"cd manual/Website3; yarn && yarn link \"webpack-external-import\" && yarn manual:prod","demo:three:debug":"cd manual/Website3; yarn && yarn link \"webpack-external-import\" && yarn manual:debug","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":"6.4.1","description":"dynamic import() external urls!","directories":{},"_nodeVersion":"10.15.3","dependencies":{"assert":"^2.0.0","loadjs":"^4.2.0","pkg-up":"^3.1.0","dimport":"^1.0.0","fs-extra":"^8.1.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^24.9.0","react":"16.8.6","eslint":"^6.4.0","webpack":"^4.40.2","prettier":"^1.19.1","cross-env":"^6.0.0","puppeteer":"^1.20.0","react-dom":"16.8.6","@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","node-cipher":"^6.3.3","webpack-cli":"^3.3.9","babel-eslint":"^10.0.3","babel-loader":"^8.0.6","concurrently":"^5.0.2","jest-resolve":"^24.9.0","schema-utils":"^2.6.1","jest-haste-map":"^24.9.0","jest-puppeteer":"^4.3.0","@babel/traverse":"^7.7.4","semantic-release":"^17.0.1","@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-config-prettier":"^6.9.0","eslint-plugin-jsx-a11y":"^6.2.3","eslint-plugin-prettier":"^3.1.2","cz-conventional-changelog":"^3.0.2","eslint-plugin-react-hooks":"^1.7.0","@babel/helper-module-imports":"^7.0.0","@babel/plugin-transform-runtime":"^7.6.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_2.0.0_1580274269664_0.07439802240621751","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":1580274269757,"_cnpm_publish_time":1580274269757,"dist-tags":{"latest":"2.2.4","next":"3.0.0-beta.3"}}