3 ms·
> It is entirely possible to eliminate unused code with the commonjs/amd/umd way with a slightly more intelligent bundler. How can you do it for this? require
by Kudos 11y ago
> It is entirely possible to eliminate unused code with the commonjs/amd/umd way with a slightly more intelligent bundler.
How can you do it for this?
require(someRuntimeVariable);
- awalGarg 11y agoIf the `someRuntimeVariable` is statically evaluate-able, then some compilers (uglifyjs, for instance) support limited inline evaluation at compile time, which could be enhanced by community effort. If not, then it won't :) But you still would have the same benefits when requiring stuff with plain string literals, and additionally you'd have the freedom to require dynamic stuff on the cost of lesser optimizations. You don't lose anything.
- jahewson 11y agoNope. If we're talking about tree-shaking (which we should be as it's the entire point in having static modules), you loose everything. That's because require(someRuntimeVariable) can refer to any module. So there's no way to exclude any of the node_modules, or any portions of any of them. So all code in all modules must be kept. No tree-shaking for you.