browserify
browserify copied to clipboard
support es module output via browser-pack
This is relevant for the "browser-pack" module, and specifically the prelude wrapper. The issue/decision to make is probably just where the best place to implement this in the browserify settings and then match that in browser-pack? With a very small additional option to configure to browser-pack's prelude, browserify can easily easily support this:
<script src="main.js" type="module"></script>
all we'd have to do is conditionally wrap the original browser-pack prelude with an export default iife. it works no problem, I've tested locally. The benefit of this might not seem apparent, but its actually a huge win for multi frame apps. When you import stuff as a module(in chrome at least), it will share the instance of the import across frames, similar to built in objects like Array. This can reduce the memory impact of multiple iframes using the same libraries from MBs to KBs.
why would you use an iife at all for ESM output?
I'm not sure how the two are related, but an iife with export default is the best way because browser-pack is already in that format and it doesnt matter. the purpose is to export a default module and not a script in order to get the benefits of type="module".
//browser-pack format basically
export default (() => 5)()
more work for no benefit to do these
let x = 5
export default x
let x = (() => 5)()
export default x
export default 5