Usually self host StreamSaver means manually (or use copy-webpack-plugin) copy mitm.html and sw.js to public folder and set up StreamSaver.mitm = '/static/mitm.html'.
But with Webpack 5 and URL Assets, one can do something like
StreamSaver.mitm = new URL('streamsaver/mitm.html?url', import.meta.url).toString() + '?sw=' + new URL('streamsaver/sw.js?url', import.meta.url).toString();
And Webpack will automatically copy mitm.html and sw.js to public folder. One bonus point is that these files now have names with hashes so they can be cached forever.
However, the sw.js path is hardcoded so the above code doesn't really work.
Usually self host StreamSaver means manually (or use copy-webpack-plugin) copy
mitm.html
andsw.js
to public folder and set upStreamSaver.mitm = '/static/mitm.html'
.But with Webpack 5 and URL Assets, one can do something like
And Webpack will automatically copy
mitm.html
andsw.js
to public folder. One bonus point is that these files now have names with hashes so they can be cached forever.However, the
sw.js
path is hardcoded so the above code doesn't really work.https://github.com/jimmywarting/StreamSaver.js/blob/cd8e32a84f951541c5be183b2b409bd17dbb16cd/mitm.html#L41
I have tested locally that some thing like this is possible (although
URLSearchParams
may have compatibility issue)