{"name":"dimport","version":"1.0.0","repository":{"type":"git","url":"git+https://github.com/lukeed/dimport.git"},"description":"Run ES Module syntax in any browser – even IE!","unpkg":"dist/index.min.js","umd:main":"dist/index.min.js","module":"dist/index.mjs","main":"dist/index.js","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"lukeed.com"},"scripts":{"build":"rm -rf nomodule legacy dist && node bin","test":"eslint src bin"},"dependencies":{"rewrite-imports":"^2.0.3"},"devDependencies":{"eslint":"^5.16.0","microbundle":"^0.11.0"},"keywords":["esm","dynamic","dynamic-import","polyfill","imports","import","module"],"gitHead":"ad364ebb37302c586a62ef00bce95f2feb759286","bugs":{"url":"https://github.com/lukeed/dimport/issues"},"homepage":"https://github.com/lukeed/dimport#readme","_id":"dimport@1.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"dist":{"integrity":"sha512-r5Cb8jvJ9YOTKQje2wrD6ncjpyDM4l94+OqgatYNzTb0viKS0/XomCjty1+F827u1pBiPt1ubSYdowZfE1L5Tw==","shasum":"d5c09564f621e7b24b2e333cccdf9b2303011644","tarball":"http://registry-npm.ywwl.com/dimport/download/dimport-1.0.0.tgz","fileCount":10,"unpackedSize":21659,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcrvhUCRA9TVsSAnZWagAAUJIP/0ES96MMXX9TqthlghXc\nLYeWtdW0CnxtVYed2qt4ztS+JuZapCDkMh5qaGl+Lj6hAHGEXbzj0cmrFPzT\nQoddHJMN6pKlc73o9TfAZER6dg259C4/pIK2c1JFa7e5XAIH96H7QqRPByv6\nNqwuNTNGxCzUU4Zualy6wZvwn8o1Rpeh+fweqTlbX+cBtk4Ujb9e77TQ5/qL\n6tvbcXEKBXRxhYiZgWbHgSphUMSI+P3Z995BXI5IAxNi5pwyPHgRdrk220/F\nXhm1SjiRUBX9jlp+rSJorykb42rw5vU0mOKBwGDcZDTV5KxUM2xioy6qt/E/\nuNnwdCgcstjYtsUcxXHFj3L9VICqlp5vqsUf98VAj9ut8o3EEyvAZW6cODRe\n/+gTxkT5zHOYbocmlqWeDszvlH3G733Tl4vCHxtE5saVpTFI2UtqLgTMKuky\nhx/+qKQgHakSr+8y4y5LT07o1PT2nbdGLypGfstSLTNqgj4ypJPFaM2BKMpt\neDnQHPdGk3MsSbvvlCfpvO1gdkhCS+uxrUr3nSbFASsZXPcF4/4R7tX8fRAW\nBgjHdYt3IoEHqrQ/6FqURGJlBkfrfLBzm2i02EZLS33CHm0jLKgkrLqJn3sH\niGBM6L1IZhlRYTtBhonu4N6EjGhETRnukgSYpgPs9oDQdhNxLTz9Qn+2Px1u\nc6Ft\r\n=zu1D\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBdYL43NtSK6K5SBfNSun0te//jFvNb1FsV8Pu4wjVUYAiBTU4IKflrPOCavSSE+tIRemkc2exR0zLNcr2eBA0JW8A=="}],"size":6393,"noattachment":false,"key":"/dimport/-/dimport-1.0.0.tgz"},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dimport_1.0.0_1554970707741_0.8545340709217226"},"_hasShrinkwrap":false,"readme":"# dimport [![Build Status](https://badgen.now.sh/travis/lukeed/dimport)](https://travis-ci.org/lukeed/dimport)\n\n> Run ES Module syntax (`import`, `import()`, and `export`) in any browser &mdash; even IE!\n\nAt its core, `dimport` is a polyfill for ES Module syntax, including [dynamic imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports)!<br>\nAnd with it, you can serve modern ESM-driven application files to any browser.\n\nWhile browsers _are_ increasing support for JavaScript modules natively, the current landscape is not easy to navigate.<br>\nFor example, many browsers _do support_ ESM syntax (aka, `import` and `export`) within `<script type=module />` tags; however, not all of these support _dynamic import_ statements since it came later.\nIn order to leverage the benefits of ESM today, a developer must choose between:\n\n* dropping support for lagging browsers\n* complicating their development process\n* building and/or distributing multiple versions of their application\n* abstaining from shipping ESM syntax at all :cry:\n\nNow, `dimport` allows the developer to ship ESM **today** to all browsers without comproimse.<br>\nBetter yet, the development and distribution processes are simplified, if not unchanged.\n\nPS: Check out the [`/examples`](/examples) directory~!\n\n<br>\n\n---\n\n***Important***\n\nThis module **does not** convert your ES2015+ syntax into ES5 or below!<br>\nWhile `dimport` may allow older browsers to parse and interpret the ESM format, it does nothing to make the _contents_ of your file(s) backwards compatible.\n\n---\n\n<br>\n\n## Modes\n\nThere are three \"versions\" of `dimport`, each of which utilize different APIs and approaches to yield full ESM compatability.\n\nPlease note that **all modes** check for native `import()` support first and foremost.<br>\nThis means that `dimport` won't do anything if it doesn't have to.\n\n#### \"module\"\n> **Size (gzip):** 675 bytes<br>\n> **Availablility:** [UMD](https://unpkg.com/dimport), [CommonJS](https://unpkg.com/dimport/dist/index.js), [ES Module](https://unpkg.com/dimport?module)<br>\n> **Requires:** `script[type=module]`, `fetch`, `Promise`, `URL`\n\nSince _static_ `import` statements are supported, this mode parses all _dynamic_ `import()`s and creates temporary `script[type=module]` tags pointing to the resource's full, canonical URL. Once the temporary script loads, the originating Promise is resolved, returning the contents.\n\n#### \"nomodule\"\n> **Size (gzip):** 918 bytes<br>\n> **Availablility:** [UMD](https://unpkg.com/dimport/nomodule), [ES Module](https://unpkg.com/dimport/nomodule/index.mjs)<br>\n> **Requires:** `fetch`, `Promise`, `URL`\n\nAll `import`, `export`, and `import()` statements are dynamically rewritten to CommonJS modules so that their contents/exports are easily returned.\n\nAny `import` statements are parsed early, ensuring full canonical URLs, and then the whole file is wrapped in a `Promise.all` chain, guaranteeing each `import` its desired module.\n\n#### \"legacy\"\n> **Size (gzip):** 1143 bytes<br>\n> **Availablility:** [UMD](https://unpkg.com/dimport/legacy), [ES Module](https://unpkg.com/dimport/legacy/index.mjs)<br>\n> **Requires:** `Promise`, `XMLHttpRequest`\n\nTakes the same approach as [\"nomodule\"](#nomodule), but inserts alternatives to `fetch` and `URL`.\n\n> **Important:** You will need to supply your own Promise polyfill for IE support.\n\n\n## Usage\n\n> Don't miss the [`/examples`](/examples) directory :sparkles:\n\nIt's possible to use `dimport` in a variety of ways!\n\nThe simplest way is to connect a few `<script/>` tags to [unpkg.com](https://unpkg.com/):\n\n```html\n<!-- Load the \"module\" version on browsers that can support it. -->\n<script type=\"module\" src=\"https://unpkg.com/dimport?module\" data-main=\"/bundle.js\"></script>\n\n<!-- Load the \"nomodule\" version on older browsers – acts as fallback! -->\n<script type=\"nomodule\" src=\"https://unpkg.com/dimport/nomodule\" data-main=\"/bundle.js\"></script>\n```\n\nIn the sample above, a browser will automatically choose which script `type` to parse.<br>\nThis means the two scripts can live side-by-side without loading your application twice!<br>\nFinally, the _same_ application file (`bundle.js`) can be used, despite the `module`-vs-`nomodule` choice.\n\nYou will also notice that the scripts have a `data-main=\"\"` attribute.<br>\nThis the path to _your application_ or _your ESM-containing file_ you wish to load.\n\nOnce `dimport` has loaded, it circles back and see that its `<script/>` caller also wants it to load a file.<br>\nAlternatively, `dimport` can load an inline script from its caller!\n\n```html\n<!-- We can use any \"mode\" here, but choosing only 1 for simplicity -->\n<script src=\"https://unpkg.com/dimport/nomodule\">\n  // Notice that we can use `import` inside a script without \"type=module\"\n  import { h, render } from 'https://unpkg.com/preact?module';\n\n  render(\n    h('h1', null, 'Hello world'),\n    document.body\n  );\n</script>\n```\n\nFinally, `dimport` is available for programmatic use and/or usable _within_ your bundle (via Webpack or Rollup)\n\n```\n$ npm install --save dimport\n```\n\n```js\nimport dimport from 'dimport';\n// or, without bundling\nimport dimport from 'https://unpkg.com/dimport?module';\n\n// Pass in URLs or file paths\n// ~> like `import()` usage\ndimport('./foo.js').then(...);\n```\n\n\n## API – Programmatic\n\n### dimport(url)\n\nReturns: `Promise`\n\nReturns a Promise containing the module.\n\n<!-- > **Note:** The Promise-requestor is cached for instant reuse. -->\n\n#### url\nType: `String`\n\nThe URL of the script to import.\n\n> **Note:** Will be transformed into a full URL if not already – see [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#Examples)\n\n\n## Browser Support\n\nThe `dimport` columns yield support for **both** static and dynamic imports.\n\n> **Important:** Chart represents ESM syntax only!<br>Not indicative of ES2015+ syntax usage within your app.\n\n| Browser | `import`<br>native | `import()`<br>native | dimport<br>module | dimport<br>nomodule | dimport<br>legacy |\n|---------|--------------------|----------------------|-------------------|---------------------|-------------------|\n| Chrome  | 61                 | 63                   | 61                | 42                  | :+1:<sup>*</sup>  |\n| Safari  | 10.1               | 11.1                 | 10.1              | 10.1                | :+1:<sup>*</sup>  |\n| Firefox | 60                 | 67                   | 60                | 39                  | :+1:<sup>*</sup>  |\n| Edge    | 16                 | :x:                  | 16                | 14                  | :+1:<sup>*</sup>  |\n| IE      | :x:                | :x:                  | :x:               | :x:                 | 7 <sup>*</sup>     |\n\n<sup>*</sup> _Indicates support with `Promise` polyfill supplied_\n\n\n## Prior Art\n\n* [`dynamic-import-ponyfill`](https://www.npmjs.com/package/dynamic-import-ponyfill) – The \"first version\" of `dimport` – now deprecated.\n* [`shimport`](https://github.com/Rich-Harris/shimport) – Patient zero. Similar to \"nomodule\" mode. Made it \"okay\" to rewrite files on the fly.\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","publish_time":1554970707866,"_cnpm_publish_time":1554970707866,"dist-tags":{"latest":"1.0.0"}}