bundle-loader
bundle-loader copied to clipboard
Advantages/disadvantages over import()
I’d like to document how this solution is different from import()/require.ensure(). This would simplify the choice between these tools: from the first sight, bundle-loader?lazy and import() are very similar, and you could get stuck thinking what to choose.
This is what I’ve found so far:
- Advantage: Per react-router docs, on additional renders, the loader calls the callback synchronously. This prevent the flashing of the loading screen.
- Disadvantage:
import()andrequire.ensure()allow handling the loading error (e.g. with.catch()), andbundle-loaderdoesn’t. - Disadvantage: Because this is a loader, the developer should either
- name a file after a specific pattern (e.g.
.lazy.js) to apply the loader to it (this requires renaming files, which is a pretty large event) or - specify the loader inline (which is a rare and webpack-specific notation).
- name a file after a specific pattern (e.g.
Are there any other known differences I’m missing?
Thanks @iamakulov for writing this up. I thought this exists because import() wasn't a thing. would like to see the opinions from the maintainers.