settings / plugins for wrapped (lazyload) required in nodejs
Hello everyone,
is there a way via settings or a custom plugin, to handle wrapped requires?
I use a npm package who have this coding:
The implemantation of the function "lazyload" looks like this:
Thanks.
One possible way is to rewrite these lazyLoad('path') to lazyLoad(() => require('path')). The later form can be statically analyzed by esbuild to make it able to bundle the file pointed by 'path'. You can do the rewrite using plugins.
On the other hand, many Node.js packages are not written in a bundler-friendly way where they may use non-analyzable imports and other code patterns. In which case I would just recommend you to externalize them using --packages=external.
Closing this question as it has been answered. That's a great answer. Either of those approaches are good ways to solve the problem.