Echo JS 0.11.0


xat 104 days ago. link 3 points
Doesn't this also make tree-shaking basicly impossible? Since the tree-shaking tool can't just strip code away because it doesn't know if that code was importet somewhere via dynamic import().
MaxArt 103 days ago. link 2 points
Only if you want a bundle that comprises every module you need.
But then again, import() will be used to load modules dynamically and *asynchronously*, so their place is actually *not* in such bundles, but in separate files that are lazy-loaded as needed.
xat 103 days ago. link 2 points
I don't agree that those modules should never be part of the bundle.

For example, you could have language files and load them with a function like "loadLang = lang => import(`./languages/${lang}`)". It is totally debatable if those language files should be part of the bundle or not and a decision the developer has to make.
MaxArt 102 days ago. link 2 points
Bundling them would break the asynchronicity behind import(), i.e. you're not lazy loading anything.

The purpose of lazy loading is to serve just the resources to make the page work and load everything else when needed in order to optimize the data that's being sent. If you bundle everything up, what are you even optimizing?
xat 100 days ago. link 1 point
Hmm, why should it break the asynchronicity behind import()? The import() implementation could just return Promise.resolve(<code of imported module>).

What I was trying to say is, that import() is also the only way to load a module based on a condition. So, if you want to load a module based on condition, you have to use import() regardless if that module is included in the bundle or not.
MaxArt 100 days ago. link 1 point
Then the module should rightfully stay out of the bundle.

If you load a module based on a condition, you're doing one of these things:

1. checking something on the client (e.g. if it supports a certain feature) and lazy-load a module (e.g. the polyfill of said feature);
2. checking on the server (e.g. the Accept-Language request header) and the load the module.

In the first case, it's pretty clear you can't (or better, shouldn't) put the module in the bundle, because it would be loaded by everyone regardless if they actually need it.
In the latter, you can't do that either, because it's a condition evaluated at runtime. Unless we're talking about generating bundle files on the fly?

What I mean is that the concept of tree-shaking entirely relies on static imports, and it's perfectly fine to keep dynamic imports out of the bundle.
Every module that could be loaded with import() must be served in separate files.

Your problems will eventually begin when those modules import things that have already been included in the bundle. That's the real catch.

If you really want to bundle everything up anyway, all you have to do is to statically import all those files, and then doing nothing with them. But then you won't even *need* to use import() anyway, because you'll already have everything you need defined in the scope. Much more, probably.
But all this has nothing to do with tree-shaking anyway.