jimmywarting / StreamSaver.js

StreamSaver writes stream to the filesystem directly asynchronous
https://jimmywarting.github.io/StreamSaver.js/example.html
MIT License
4k stars 415 forks source link

Switch to ESM #333

Open erjonify opened 11 months ago

erjonify commented 11 months ago

closes #185

jimmywarting commented 11 months ago

https://github.com/jimmywarting/StreamSaver.js/blob/5b372f7ba5f1e82ef80e2466023930ee2c616a28/StreamSaver.js#L5-L12

We can remove all of this:

<script src="https://cdn.jsdelivr.net/npm/web-streams-polyfill@2.0.2/dist/ponyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/streamsaver@2.0.3/StreamSaver.min.js"></script>
<script>
  import streamSaver from 'streamsaver'
  const streamSaver = require('streamsaver')
  const streamSaver = window.streamSaver
</script>

and replace it with:

<script type="importmap">
  {
    "imports": {
      "streamsaver/StreamSaver.js": "https://cdn.jsdelivr.net/npm/streamsaver@3/StreamSaver.min.js"
    }
  }
</script>
<script type="module">
  // either one works fine, the later one requires importmaps or a web bundler. 
  import streamSaver from 'https://cdn.jsdelivr.net/npm/streamsaver@3/StreamSaver.min.js'
  import streamSaver from 'streamsaver/StreamSaver.min.js'

  const uInt8 = new TextEncoder().encode('StreamSaver is awesome')
  ...
</script>
jimmywarting commented 11 months ago

Just realized that you created PR #333 (3 threes, 1/3 of 999, threes as in the same length as the amount of number there are in 333) it's also 3:33pm here. and 3 days since you created your first/last commit in this PR! coincident? I think not! 3 is a magic number ✨

erjonify commented 11 months ago
  • type="module"

@jimmywarting , i did some small changes, feel free to complete the rest :)