{"name":"dimport","version":"0.1.5","repository":{"type":"git","url":"git+https://github.com/lukeed/dimport.git"},"description":"WIP","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","imports","import","module"],"gitHead":"66fc493c55f5ecbf084bd9cf858686517103ee9a","bugs":{"url":"https://github.com/lukeed/dimport/issues"},"homepage":"https://github.com/lukeed/dimport#readme","_id":"dimport@0.1.5","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"dist":{"integrity":"sha512-+U2dsxEqY2g1znpWYnt7ig4wzJJguReWLH4g4ZLB6ZbC7y1CHRdgexMtyuWRxh7lYM5c2CgtGrMIiniyjE578Q==","shasum":"897cdec4fcbdf045f2191d1b68a73eb9873ad9b6","tarball":"http://registry-npm.ywwl.com/dimport/download/dimport-0.1.5.tgz","fileCount":10,"unpackedSize":16592,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcrj+wCRA9TVsSAnZWagAAyDMP/RphcTmi3jNMajCgQ0in\nYrB2ghDLbL/EgefpbiYlwjFHBUF0pTrfgJpsxQ8gDskXV8HvTO/BlmlUrV8S\nyCPfMo3wKc9suQlbXTVbHxViCRXaVkHuEVgC9k8pstOHgHWOrhVhJ5XZzufa\nAk2rJ5GmzsXk4R0TAVOdTXSlMYhs4V41k5uFueMrXMnUMZqs+tlckPleIqY7\nROXK34/8BgrI8T10qaWYx8/VI/Em03WV6P2VpiVB5PEeOIdLN99wih1fOvA4\nkXF9mlDqX4UAw17eq+NBfPUYBL7iB3C9QYewJvwAf0WS76CYghsxJjanfYZe\nq3Ri4UK4yY0ocmS/dpEytgFlJe8lPzKoAZ6zEEgewDSmuYixblDxvz3XZgYc\nf/mRh2gFxwsXDuOaSBt/t10XXSsJuz15lba15aCyRl5lm428FEb9oAri2yeY\nJFB7/Bi1GP2YEmMX61yD7xQEAmNLm26LdtQqdL89O8m865yq1Cz0663uaU+/\n8SpAPPAjOEqoeRbAAOhPhh5mSXYGRv5dnT4Tf4PIJeM/+pqJidmx9V2NSu2A\nSuA9sNkDk8VDKtOqGFP84hzw4V9ZUX5BlTkJ0BmhzcjgRQYQ9ytNFPmbsl3l\n9MB9SJe+1G26VjZq7w78U0T4ymHxH4Jc2ALzVsPyAs7Q2GAS476uOPgIaK8p\nlzAn\r\n=Bk30\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC6q7sHiN+Q9qryK+z6k1L22OuR8PJ0hJXS+WJ3r8ECmQIgdh8oRhOUeYoMhgX2NbEN5EEYwvXqjRAtoTAyR5rFhLk="}],"size":4742,"noattachment":false,"key":"/dimport/-/dimport-0.1.5.tgz"},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dimport_0.1.5_1554923439874_0.19094974013710608"},"_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":1554923439985,"_cnpm_publish_time":1554923439985,"dist-tags":{"latest":"1.0.0"}}