{"name":"webpack-external-import","version":"2.2.4","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":"MIT","_id":"webpack-external-import@2.2.4","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":"954c0a43f27af5e01db0c6454eee8232cebce8a5","tarball":"http://registry-npm.ywwl.com/webpack-external-import/download/webpack-external-import-2.2.4.tgz","fileCount":16,"integrity":"sha512-yJUHeu/UaZ8o0gCQyor6nsjEVdgc3ao8w7E6j28Dh1BanMxnqm0PumdElh2C5z/DMTcw1knQbpEArRo6/knNog==","signatures":[{"sig":"MEQCIGmiXyYEkxeaDiqn1UGClM/bXNXjK78hBTXBffGRID9NAiBNhv3EtWDLx+1E24hUsX4HFyWhJPKCjwjgV6WQwHkBlA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":82960,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJevdKoCRA9TVsSAnZWagAATFAP/jYVf5NO3TZXnD/eNIxi\niOKA/48I2YCpwg1ANiY2gxXhKnHzYCy8lhE1cjEm4Ni6uVeoAY2aoyGprOSd\nLWeuXedCeKYuKYoquDrl/WGgK2eve+f1oaUVUbmpyJcwBMuQwIZKS0bBn0G/\nTE0X2T1cbPNIzXUBdc7DHHtrSqTLYlV8bGQCbB7PRNM0Jby1xmRGT2QBtx6q\n/nmlG6plBCv0MeP/QbjUKNgm7gn6HMpvQDWjzYU6D5sE1pDIj6iPXdkCmGOA\nFFCbpzFoXDZwEYY4/P/PHyrFjutVeBeI6z0SFRWr2vtA0ABwHeG3HUnsgLdQ\nBdflwCoByz4tUniF0SqOiaOOtee5R8maN2z1m7EwbATdvkGZugGvsFVZraA9\nXqOsC5suAGubMcqB5CxvD7G5hUrkeAKfbyF4+NxiqjzbLOfYZnVEbhxSHI7d\n23TW02YzHqnZ0ytcikDZK5YE9eH7cEpKmXd43WLHlPwPwA+D19tSly3fdUTw\ntO58wCNriH4mMu0SuoKVxOUVQSWH2LxAMt6QniOi41a5kBmXqWVXZNlgajdW\nUWyT1YP92mBkaKZiwPgm/7UTolTNqN2ivhkVL3gWt7w23u37tPl3sp0nzitx\np/7TCrn/SvCAxP+UkjbyCrdvbKMUk7zMpn652kLkyjqtdDylZoQLp7B0U2io\nPeRJ\r\n=KPhl\r\n-----END PGP SIGNATURE-----\r\n","size":22784,"noattachment":false,"key":"/webpack-external-import/-/webpack-external-import-2.2.4.tgz"},"babel":{"env":{"production":{"plugins":["transform-remove-console"]}},"plugins":["@babel/plugin-proposal-optional-chaining"],"presets":["@babel/preset-env","@babel/preset-react"]},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"gitHead":"ec226f899b62107d25455145ebf01d21173ef4e3","scripts":{"demo":"cd manual; yarn && cd ../; concurrently \"yarn compile\"  \"yarn demo:one\"  \"yarn demo:two\"  \"yarn demo:three\"","lint":"eslint --ext .js,.ts,.tsx src --fix","test":"yarn lint","commit":"npx git-cz","compile":"rm -rf webpack index.js corsImport.js react.js polyfill.js; babel src -d .","prepare":"BABEL_ENV=production yarn compile","demo:one":"cd manual/website1; yarn manual:dev","demo:two":"cd manual/website2; yarn manual:dev","demo:fast":"yarn compile && yarn demo:one:fast | yarn demo:two:fast","demo:prod":"cd manual; yarn && cd ../; concurrently \"yarn kill-ports\" \"yarn compile\" \"yarn demo:one:prod\" \"yarn demo:two:prod\" \"yarn demo:three:prod \"","demo:debug":"cd manual; yarn && cd ../; concurrently \"yarn kill-ports\" \"yarn compile\" \"yarn demo:one\" \"yarn demo:two:debug\" \"yarn demo:three\"","demo:three":"cd manual/website3; 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 manual:prod","demo:two:prod":"cd manual/website2; yarn && yarn manual:prod","demo:one:debug":"cd manual/website1; yarn && yarn manual:debug","demo:two:debug":"cd manual/website2; yarn && yarn manual:debug","demo:three:prod":"cd manual/website3; yarn && yarn manual:prod","demo:three:debug":"cd manual/website3; yarn && 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.13.7","description":"dynamic import() external urls!","directories":{},"_nodeVersion":"10.20.1","dependencies":{"mem":"^6.0.1","assert":"^2.0.0","loadjs":"^4.2.0","pkg-up":"^3.1.0","dimport":"^1.0.0","tapable":"^1.1.3","fs-extra":"^8.1.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"25.1.0","react":"16.8.6","eslint":"6.8.0","marked":"0.7.0","webpack":"4.41.6","flow-bin":"0.119.1","prettier":"1.19.1","cross-env":"7.0.0","puppeteer":"2.1.1","react-dom":"16.8.6","@babel/cli":"7.8.4","babel-core":"7.0.0-bridge.0","commitizen":"4.0.3","paralleljs":"0.2.1","prop-types":"15.7.2","source-map":"0.7.3","@babel/core":"7.8.4","babel-watch":"7.0.0","node-cipher":"6.3.3","webpack-cli":"3.3.11","babel-eslint":"10.0.3","babel-loader":"8.0.6","concurrently":"5.1.0","jest-resolve":"25.1.0","schema-utils":"2.6.4","jest-haste-map":"25.1.0","jest-puppeteer":"4.4.0","@babel/traverse":"7.8.4","semantic-release":"17.0.4","@babel/preset-env":"7.8.4","webpack-dev-server":"3.10.3","@babel/preset-react":"7.8.3","eslint-plugin-react":"7.18.3","html-webpack-plugin":"3.2.0","regenerator-runtime":"0.13.3","eslint-config-airbnb":"18.0.1","eslint-plugin-import":"2.20.1","travis-github-status":"1.6.3","eslint-config-prettier":"6.10.0","eslint-plugin-jsx-a11y":"6.2.3","eslint-plugin-prettier":"3.1.2","cz-conventional-changelog":"3.1.0","eslint-plugin-react-hooks":"1.7.0","@babel/helper-module-imports":"7.8.3","@babel/plugin-transform-runtime":"7.8.3","@babel/plugin-transform-react-jsx":"7.8.3","@babel/plugin-syntax-dynamic-import":"7.8.3","babel-plugin-transform-remove-console":"6.9.4","@babel/plugin-proposal-class-properties":"7.8.3","@babel/plugin-proposal-optional-chaining":"7.8.3"},"peerDependencies":{"webpack":"^4.40.2"},"_npmOperationalInternal":{"tmp":"tmp/webpack-external-import_2.2.4_1589498535511_0.2938789606176948","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":1589498535643,"_cnpm_publish_time":1589498535643,"dist-tags":{"latest":"2.2.4","next":"3.0.0-beta.3"}}