showing results for - "inline javascript modules"
Bautista
18 Jan 2019
1<script type="module" data-info="https://stackoverflow.com/a/43834063">let l,e,t
2='script',p=/(from\s+|import\s+)['"](#[\w\-]+)['"]/g,x='textContent',d=document,
3s,o;for(o of d.querySelectorAll(t+'[type=inline-module]'))l=d.createElement(t),o
4.id?l.id=o.id:0,l.type='module',l[x]=o[x].replace(p,(u,a,z)=>(e=d.querySelector(
5t+z+'[type=module][src]'))?a+`/* ${z} */'${e.src}'`:u),l.src=URL.createObjectURL
6(new Blob([l[x]],{type:'application/java'+t})),o.replaceWith(l)//inline</script>
7
8<script type="inline-module" id="utils">
9  let n = 1;
10  
11  export const log = message => {
12    const output = document.createElement('pre');
13    output.textContent = `[${n++}] ${message}`;
14    document.body.appendChild(output);
15  };
16</script>
17
18<script type="inline-module" id="dogs">
19  import {log} from '#utils';
20  
21  log("Exporting dog names.");
22  
23  export const names = ["Kayla", "Bentley", "Gilligan"];
24</script>
25
26<script type="inline-module">
27  import {log} from '#utils';
28  import {names as dogNames} from '#dogs';
29  
30  log(`Imported dog names: ${dogNames.join(", ")}.`);
31</script>