This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
function e(e,t){t.onerror=t.onload=null,URL.revokeObjectURL(t.temp),URL.revokeObjectURL(t.src),delete window[e],t.remove()}function t(e,t){return URL.createObjectURL(new Blob([t.replace(/(^|\s|;)(import\s*)(\(|.*from\s*|)['"]([^'"]+)['"]/gi,function(t,r,n,o,i){return r+("("==o?"window.dimport":n)+o+"'"+new URL(i,e)+"'"}).replace(/(^|\s|;)(import)(?=\()/g,"$1window.dimport")],{type:"application/javascript"}))}var r={};function n(o){o=new URL(o,location.href).href;try{return new Function("return import('"+o+"')").call()}catch(i){return r[o]?Promise.resolve(r[o]):fetch(o).then(function(e){return e.text()}).then(function(c){return window.dimport=n,new Promise(function(n,m,a){i=document.createElement("script"),a="$"+Math.random().toString(32).slice(2),i.type="module",i.onerror=function(){e(a,i),m(new TypeError("Failed to fetch dynamically imported module: "+o))},i.onload=function(){n(r[o]=window[a]),e(a,i)},i.temp=t(o,c),i.src=t(o,"import * as m from '"+i.temp+"';window."+a+"=m;"),document.head.appendChild(i)})})}}var o=void 0!==document&&document.currentScript||document.querySelector("script[data-main]");o&&(o.text?n(t(location.href,o.text)):(o=o.getAttribute("data-main"))&&n(o)),module.exports=n;
+1
View File
@@ -0,0 +1 @@
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.dimport=t()}(this,function(){function e(e,t){t.onerror=t.onload=null,URL.revokeObjectURL(t.temp),URL.revokeObjectURL(t.src),delete window[e],t.remove()}function t(e,t){return URL.createObjectURL(new Blob([t.replace(/(^|\s|;)(import\s*)(\(|.*from\s*|)['"]([^'"]+)['"]/gi,function(t,n,o,r,i){return n+("("==r?"window.dimport":o)+r+"'"+new URL(i,e)+"'"}).replace(/(^|\s|;)(import)(?=\()/g,"$1window.dimport")],{type:"application/javascript"}))}var n={};function o(r){r=new URL(r,location.href).href;try{return new Function("return import('"+r+"')").call()}catch(i){return n[r]?Promise.resolve(n[r]):fetch(r).then(function(e){return e.text()}).then(function(c){return window.dimport=o,new Promise(function(o,d,u){i=document.createElement("script"),u="$"+Math.random().toString(32).slice(2),i.type="module",i.onerror=function(){e(u,i),d(new TypeError("Failed to fetch dynamically imported module: "+r))},i.onload=function(){o(n[r]=window[u]),e(u,i)},i.temp=t(r,c),i.src=t(r,"import * as m from '"+i.temp+"';window."+u+"=m;"),document.head.appendChild(i)})})}}var r=void 0!==document&&document.currentScript||document.querySelector("script[data-main]");return r&&(r.text?o(t(location.href,r.text)):(r=r.getAttribute("data-main"))&&o(r)),o});
+1
View File
@@ -0,0 +1 @@
function e(e,t){t.onerror=t.onload=null,URL.revokeObjectURL(t.temp),URL.revokeObjectURL(t.src),delete window[e],t.remove()}function t(e,t){return URL.createObjectURL(new Blob([t.replace(/(^|\s|;)(import\s*)(\(|.*from\s*|)['"]([^'"]+)['"]/gi,function(t,r,n,o,i){return r+("("==o?"window.dimport":n)+o+"'"+new URL(i,e)+"'"}).replace(/(^|\s|;)(import)(?=\()/g,"$1window.dimport")],{type:"application/javascript"}))}var r={};function n(o){o=new URL(o,location.href).href;try{return new Function("return import('"+o+"')").call()}catch(i){return r[o]?Promise.resolve(r[o]):fetch(o).then(function(e){return e.text()}).then(function(c){return window.dimport=n,new Promise(function(n,a,d){i=document.createElement("script"),d="$"+Math.random().toString(32).slice(2),i.type="module",i.onerror=function(){e(d,i),a(new TypeError("Failed to fetch dynamically imported module: "+o))},i.onload=function(){n(r[o]=window[d]),e(d,i)},i.temp=t(o,c),i.src=t(o,"import * as m from '"+i.temp+"';window."+d+"=m;"),document.head.appendChild(i)})})}}var o=void 0!==document&&document.currentScript||document.querySelector("script[data-main]");o&&(o.text?n(t(location.href,o.text)):(o=o.getAttribute("data-main"))&&n(o));export default n;
+1
View File
@@ -0,0 +1 @@
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.dimport=e()}(this,function(){var t=/(^|;|\s+)import\s*['"]([^'"]+)['"](?=($|;|\s))/gi,e=/(^|[;\s]+)?import\s*(\*\s*as)?\s*(\w*?)\s*,?\s*(?:\{([\s\S]*?)\})?\s*from\s*['"]([^'"]+)['"];?/gi;function n(t,e){for(var n=[];t.length;)n.push(t.shift().trim().replace(/ as /g,":"));return"const { "+n.join(", ")+" } = "+e+";"}var r={};function o(r,o){window.dimport=i;var s,p=[],u=[],a={exports:{}},c=function(r,o){return r.replace(t,"$1"+(o=o||"require")+"('$2')").replace(e,function(t,e,r,i,s,p){return(e||"")+function(t,e,r,o){return e=o+"('"+e+"')",t.length&&!r?n(t,e):"const "+r+" = "+e+";"+(t.length?"\n"+n(t,r):"")}(s?s.split(","):[],p,i,o)})}(o.replace(/(^|\s|;)(import\s*)(\(|.*from\s*|)['"]([^'"]+)['"];?/gi,function(t,e,n,o,i){return i="'"+new URL(i,r).href+"'",e+n+o+("("==o?i:"'$dimport["+(u.push(i)-1)+"]';")}).replace(/(^|\s|;)(import)(?=\()/g,"$1window.dimport").replace(/export default/,"module.exports =").replace(/export\s+(const|function|class|let|var)\s+(.+?)(?=(\(|\s|=))/gi,function(t,e,n){return p.push(n)&&e+" "+n}).replace(/export\s*\{([\s\S]*?)\}/gi,function(t,e){for(var n,r="",o=e.split(",");n=o.shift();)r+="exports."+((n=n.trim().split(" as "))[1]||n[0])+" = "+n[0]+";\n";return r}),"eval");for(p.sort();s=p.shift();)c+="\nexports."+s+" = "+s+";";return Promise.resolve(new Function("module","exports",u.length?"return Promise.all(["+u.join()+"].map(window.dimport)).then(function($dimport){"+c+"});":c)(a,a.exports)).then(function(){return a.exports.default=a.exports.default||a.exports,a.exports})}function i(t){t=function(t,e,n,r){return/^https?:\/\//.test(t)?t:((n=document.createElement("a")).href=e,"/"==t[0]||"/"===n.pathname?n.origin+"/"+t:(r=n.pathname.split("/"),e=t.split("../"),n.origin+r.slice(0,r.length-Math.max(e.length-1,1)).concat(e.pop()).join("/")))}(t,location.href);try{return new Function("return import('"+t+"')").call()}catch(e){return r[t]?Promise.resolve(r[t]):new Promise(function(e,n,i){(i=new XMLHttpRequest).onerror=n,i.open("GET",t,!0),i.onload=function(){i.status>=400?n(new TypeError("Failed to fetch dynamically imported module: "+t)):o(t,i.responseText).then(function(n){return e(r[t]=n)})},i.send()})}}var s=void 0!==document&&document.querySelector("script[data-main]");return s&&(s.text?o(location.href,s.text):(s=s.getAttribute("data-main"))&&i(s)),i});
+1
View File
@@ -0,0 +1 @@
var t=/(^|;|\s+)import\s*['"]([^'"]+)['"](?=($|;|\s))/gi,e=/(^|[;\s]+)?import\s*(\*\s*as)?\s*(\w*?)\s*,?\s*(?:\{([\s\S]*?)\})?\s*from\s*['"]([^'"]+)['"];?/gi;function r(t,e){for(var r=[];t.length;)r.push(t.shift().trim().replace(/ as /g,":"));return"const { "+r.join(", ")+" } = "+e+";"}var n={};function o(n,o){window.dimport=i;var s,p=[],u=[],a={exports:{}},c=function(n,o){return n.replace(t,"$1"+(o=o||"require")+"('$2')").replace(e,function(t,e,n,i,s,p){return(e||"")+function(t,e,n,o){return e=o+"('"+e+"')",t.length&&!n?r(t,e):"const "+n+" = "+e+";"+(t.length?"\n"+r(t,n):"")}(s?s.split(","):[],p,i,o)})}(o.replace(/(^|\s|;)(import\s*)(\(|.*from\s*|)['"]([^'"]+)['"];?/gi,function(t,e,r,o,i){return i="'"+new URL(i,n).href+"'",e+r+o+("("==o?i:"'$dimport["+(u.push(i)-1)+"]';")}).replace(/(^|\s|;)(import)(?=\()/g,"$1window.dimport").replace(/export default/,"module.exports =").replace(/export\s+(const|function|class|let|var)\s+(.+?)(?=(\(|\s|=))/gi,function(t,e,r){return p.push(r)&&e+" "+r}).replace(/export\s*\{([\s\S]*?)\}/gi,function(t,e){for(var r,n="",o=e.split(",");r=o.shift();)n+="exports."+((r=r.trim().split(" as "))[1]||r[0])+" = "+r[0]+";\n";return n}),"eval");for(p.sort();s=p.shift();)c+="\nexports."+s+" = "+s+";";return Promise.resolve(new Function("module","exports",u.length?"return Promise.all(["+u.join()+"].map(window.dimport)).then(function($dimport){"+c+"});":c)(a,a.exports)).then(function(){return a.exports.default=a.exports.default||a.exports,a.exports})}function i(t){t=function(t,e,r,n){return/^https?:\/\//.test(t)?t:((r=document.createElement("a")).href=e,"/"==t[0]||"/"===r.pathname?r.origin+"/"+t:(n=r.pathname.split("/"),e=t.split("../"),r.origin+n.slice(0,n.length-Math.max(e.length-1,1)).concat(e.pop()).join("/")))}(t,location.href);try{return new Function("return import('"+t+"')").call()}catch(e){return n[t]?Promise.resolve(n[t]):new Promise(function(e,r,i){(i=new XMLHttpRequest).onerror=r,i.open("GET",t,!0),i.onload=function(){i.status>=400?r(new TypeError("Failed to fetch dynamically imported module: "+t)):o(t,i.responseText).then(function(r){return e(n[t]=r)})},i.send()})}}var s=void 0!==document&&document.querySelector("script[data-main]");s&&(s.text?o(location.href,s.text):(s=s.getAttribute("data-main"))&&i(s));export default i;
+9
View File
@@ -0,0 +1,9 @@
MIT License
Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+1
View File
@@ -0,0 +1 @@
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.dimport=e()}(this,function(){var t=/(^|;|\s+)import\s*['"]([^'"]+)['"](?=($|;|\s))/gi,e=/(^|[;\s]+)?import\s*(\*\s*as)?\s*(\w*?)\s*,?\s*(?:\{([\s\S]*?)\})?\s*from\s*['"]([^'"]+)['"];?/gi;function r(t,e){for(var r=[];t.length;)r.push(t.shift().trim().replace(/ as /g,":"));return"const { "+r.join(", ")+" } = "+e+";"}var n={};function o(n,o){window.dimport=i;var s,u=[],p=[],c={exports:{}},f=function(n,o){return n.replace(t,"$1"+(o=o||"require")+"('$2')").replace(e,function(t,e,n,i,s,u){return(e||"")+function(t,e,n,o){return e=o+"('"+e+"')",t.length&&!n?r(t,e):"const "+n+" = "+e+";"+(t.length?"\n"+r(t,n):"")}(s?s.split(","):[],u,i,o)})}(o.replace(/(^|\s|;)(import\s*)(\(|.*from\s*|)['"]([^'"]+)['"];?/gi,function(t,e,r,o,i){return i="'"+new URL(i,n).href+"'",e+r+o+("("==o?i:"'$dimport["+(p.push(i)-1)+"]';")}).replace(/(^|\s|;)(import)(?=\()/g,"$1window.dimport").replace(/export default/,"module.exports =").replace(/export\s+(const|function|class|let|var)\s+(.+?)(?=(\(|\s|=))/gi,function(t,e,r){return u.push(r)&&e+" "+r}).replace(/export\s*\{([\s\S]*?)\}/gi,function(t,e){for(var r,n="",o=e.split(",");r=o.shift();)n+="exports."+((r=r.trim().split(" as "))[1]||r[0])+" = "+r[0]+";\n";return n}),"eval");for(u.sort();s=u.shift();)f+="\nexports."+s+" = "+s+";";return Promise.resolve(new Function("module","exports",p.length?"return Promise.all(["+p.join()+"].map(window.dimport)).then(function($dimport){"+f+"});":f)(c,c.exports)).then(function(){return c.exports.default=c.exports.default||c.exports,c.exports})}function i(t){t=new URL(t,location.href).href;try{return new Function("return import('"+t+"')").call()}catch(e){return n[t]?Promise.resolve(n[t]):fetch(t).then(function(t){return t.text()}).then(o.bind(o,t)).then(function(e){return n[t]=e})}}var s=void 0!==document&&document.currentScript||document.querySelector("script[data-main]");return s&&(s.text?o(location.href,s.text):(s=s.getAttribute("data-main"))&&i(s)),i});
+1
View File
@@ -0,0 +1 @@
var t=/(^|;|\s+)import\s*['"]([^'"]+)['"](?=($|;|\s))/gi,r=/(^|[;\s]+)?import\s*(\*\s*as)?\s*(\w*?)\s*,?\s*(?:\{([\s\S]*?)\})?\s*from\s*['"]([^'"]+)['"];?/gi;function e(t,r){for(var e=[];t.length;)e.push(t.shift().trim().replace(/ as /g,":"));return"const { "+e.join(", ")+" } = "+r+";"}var n={};function o(n,o){window.dimport=i;var s,u=[],c=[],p={exports:{}},a=function(n,o){return n.replace(t,"$1"+(o=o||"require")+"('$2')").replace(r,function(t,r,n,i,s,u){return(r||"")+function(t,r,n,o){return r=o+"('"+r+"')",t.length&&!n?e(t,r):"const "+n+" = "+r+";"+(t.length?"\n"+e(t,n):"")}(s?s.split(","):[],u,i,o)})}(o.replace(/(^|\s|;)(import\s*)(\(|.*from\s*|)['"]([^'"]+)['"];?/gi,function(t,r,e,o,i){return i="'"+new URL(i,n).href+"'",r+e+o+("("==o?i:"'$dimport["+(c.push(i)-1)+"]';")}).replace(/(^|\s|;)(import)(?=\()/g,"$1window.dimport").replace(/export default/,"module.exports =").replace(/export\s+(const|function|class|let|var)\s+(.+?)(?=(\(|\s|=))/gi,function(t,r,e){return u.push(e)&&r+" "+e}).replace(/export\s*\{([\s\S]*?)\}/gi,function(t,r){for(var e,n="",o=r.split(",");e=o.shift();)n+="exports."+((e=e.trim().split(" as "))[1]||e[0])+" = "+e[0]+";\n";return n}),"eval");for(u.sort();s=u.shift();)a+="\nexports."+s+" = "+s+";";return Promise.resolve(new Function("module","exports",c.length?"return Promise.all(["+c.join()+"].map(window.dimport)).then(function($dimport){"+a+"});":a)(p,p.exports)).then(function(){return p.exports.default=p.exports.default||p.exports,p.exports})}function i(t){t=new URL(t,location.href).href;try{return new Function("return import('"+t+"')").call()}catch(r){return n[t]?Promise.resolve(n[t]):fetch(t).then(function(t){return t.text()}).then(o.bind(o,t)).then(function(r){return n[t]=r})}}var s=void 0!==document&&document.currentScript||document.querySelector("script[data-main]");s&&(s.text?o(location.href,s.text):(s=s.getAttribute("data-main"))&&i(s));export default i;
+76
View File
@@ -0,0 +1,76 @@
{
"_args": [
[
"dimport@1.0.0",
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
]
],
"_from": "dimport@1.0.0",
"_id": "dimport@1.0.0",
"_inBundle": false,
"_integrity": "sha512-r5Cb8jvJ9YOTKQje2wrD6ncjpyDM4l94+OqgatYNzTb0viKS0/XomCjty1+F827u1pBiPt1ubSYdowZfE1L5Tw==",
"_location": "/dimport",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "dimport@1.0.0",
"name": "dimport",
"escapedName": "dimport",
"rawSpec": "1.0.0",
"saveSpec": null,
"fetchSpec": "1.0.0"
},
"_requiredBy": [
"/webpack-external-import"
],
"_resolved": "https://registry.npmjs.org/dimport/-/dimport-1.0.0.tgz",
"_spec": "1.0.0",
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
"author": {
"name": "Luke Edwards",
"email": "luke.edwards05@gmail.com",
"url": "lukeed.com"
},
"bugs": {
"url": "https://github.com/lukeed/dimport/issues"
},
"dependencies": {
"rewrite-imports": "^2.0.3"
},
"description": "Run ES Module syntax in any browser even IE!",
"devDependencies": {
"eslint": "^5.16.0",
"microbundle": "^0.11.0"
},
"files": [
"dist",
"legacy",
"nomodule"
],
"homepage": "https://github.com/lukeed/dimport#readme",
"keywords": [
"esm",
"dynamic",
"dynamic-import",
"polyfill",
"imports",
"import",
"module"
],
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
"name": "dimport",
"repository": {
"type": "git",
"url": "git+https://github.com/lukeed/dimport.git"
},
"scripts": {
"build": "rm -rf nomodule legacy dist && node bin",
"test": "eslint src bin"
},
"umd:main": "dist/index.min.js",
"unpkg": "dist/index.min.js",
"version": "1.0.0"
}
+166
View File
@@ -0,0 +1,166 @@
# dimport [![Build Status](https://badgen.now.sh/travis/lukeed/dimport)](https://travis-ci.org/lukeed/dimport)
> Run ES Module syntax (`import`, `import()`, and `export`) in any browser &mdash; even IE!
At 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>
And with it, you can serve modern ESM-driven application files to any browser.
While browsers _are_ increasing support for JavaScript modules natively, the current landscape is not easy to navigate.<br>
For 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.
In order to leverage the benefits of ESM today, a developer must choose between:
* dropping support for lagging browsers
* complicating their development process
* building and/or distributing multiple versions of their application
* abstaining from shipping ESM syntax at all :cry:
Now, `dimport` allows the developer to ship ESM **today** to all browsers without comproimse.<br>
Better yet, the development and distribution processes are simplified, if not unchanged.
PS: Check out the [`/examples`](/examples) directory~!
<br>
---
***Important***
This module **does not** convert your ES2015+ syntax into ES5 or below!<br>
While `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.
---
<br>
## Modes
There are three "versions" of `dimport`, each of which utilize different APIs and approaches to yield full ESM compatability.
Please note that **all modes** check for native `import()` support first and foremost.<br>
This means that `dimport` won't do anything if it doesn't have to.
#### "module"
> **Size (gzip):** 675 bytes<br>
> **Availablility:** [UMD](https://unpkg.com/dimport), [CommonJS](https://unpkg.com/dimport/dist/index.js), [ES Module](https://unpkg.com/dimport?module)<br>
> **Requires:** `script[type=module]`, `fetch`, `Promise`, `URL`
Since _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.
#### "nomodule"
> **Size (gzip):** 918 bytes<br>
> **Availablility:** [UMD](https://unpkg.com/dimport/nomodule), [ES Module](https://unpkg.com/dimport/nomodule/index.mjs)<br>
> **Requires:** `fetch`, `Promise`, `URL`
All `import`, `export`, and `import()` statements are dynamically rewritten to CommonJS modules so that their contents/exports are easily returned.
Any `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.
#### "legacy"
> **Size (gzip):** 1143 bytes<br>
> **Availablility:** [UMD](https://unpkg.com/dimport/legacy), [ES Module](https://unpkg.com/dimport/legacy/index.mjs)<br>
> **Requires:** `Promise`, `XMLHttpRequest`
Takes the same approach as ["nomodule"](#nomodule), but inserts alternatives to `fetch` and `URL`.
> **Important:** You will need to supply your own Promise polyfill for IE support.
## Usage
> Don't miss the [`/examples`](/examples) directory :sparkles:
It's possible to use `dimport` in a variety of ways!
The simplest way is to connect a few `<script/>` tags to [unpkg.com](https://unpkg.com/):
```html
<!-- Load the "module" version on browsers that can support it. -->
<script type="module" src="https://unpkg.com/dimport?module" data-main="/bundle.js"></script>
<!-- Load the "nomodule" version on older browsers  acts as fallback! -->
<script type="nomodule" src="https://unpkg.com/dimport/nomodule" data-main="/bundle.js"></script>
```
In the sample above, a browser will automatically choose which script `type` to parse.<br>
This means the two scripts can live side-by-side without loading your application twice!<br>
Finally, the _same_ application file (`bundle.js`) can be used, despite the `module`-vs-`nomodule` choice.
You will also notice that the scripts have a `data-main=""` attribute.<br>
This the path to _your application_ or _your ESM-containing file_ you wish to load.
Once `dimport` has loaded, it circles back and see that its `<script/>` caller also wants it to load a file.<br>
Alternatively, `dimport` can load an inline script from its caller!
```html
<!-- We can use any "mode" here, but choosing only 1 for simplicity -->
<script src="https://unpkg.com/dimport/nomodule">
// Notice that we can use `import` inside a script without "type=module"
import { h, render } from 'https://unpkg.com/preact?module';
render(
h('h1', null, 'Hello world'),
document.body
);
</script>
```
Finally, `dimport` is available for programmatic use and/or usable _within_ your bundle (via Webpack or Rollup)
```
$ npm install --save dimport
```
```js
import dimport from 'dimport';
// or, without bundling
import dimport from 'https://unpkg.com/dimport?module';
// Pass in URLs or file paths
// ~> like `import()` usage
dimport('./foo.js').then(...);
```
## API Programmatic
### dimport(url)
Returns: `Promise`
Returns a Promise containing the module.
<!-- > **Note:** The Promise-requestor is cached for instant reuse. -->
#### url
Type: `String`
The URL of the script to import.
> **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)
## Browser Support
The `dimport` columns yield support for **both** static and dynamic imports.
> **Important:** Chart represents ESM syntax only!<br>Not indicative of ES2015+ syntax usage within your app.
| Browser | `import`<br>native | `import()`<br>native | dimport<br>module | dimport<br>nomodule | dimport<br>legacy |
|---------|--------------------|----------------------|-------------------|---------------------|-------------------|
| Chrome | 61 | 63 | 61 | 42 | :+1:<sup>*</sup> |
| Safari | 10.1 | 11.1 | 10.1 | 10.1 | :+1:<sup>*</sup> |
| Firefox | 60 | 67 | 60 | 39 | :+1:<sup>*</sup> |
| Edge | 16 | :x: | 16 | 14 | :+1:<sup>*</sup> |
| IE | :x: | :x: | :x: | :x: | 7 <sup>*</sup> |
<sup>*</sup> _Indicates support with `Promise` polyfill supplied_
## Prior Art
* [`dynamic-import-ponyfill`](https://www.npmjs.com/package/dynamic-import-ponyfill) The "first version" of `dimport` now deprecated.
* [`shimport`](https://github.com/Rich-Harris/shimport)  Patient zero. Similar to "nomodule" mode. Made it "okay" to rewrite files on the fly.
## License
MIT © [Luke Edwards](https://lukeed.com)