Closed zdila closed 3 years ago
For code splitting you can already use normal modules (one module per file/chunk).
This could be useful for the opposite: to easily put multiple modules in the same file/chunk.
Please see the Bundling section in the FAQ of the README :)
Putting multiple modules in the same chunk is default behaviour of Webpack (ie. it compiles many source js files to a single one).
What I am missing is to have a single source js file compiled by webpack to multiple chunks.
Oh something like this?
element.addEventListener("click", () => import(clickHandler).then(m => m.default()));
// This module is not used immediately, we can tell webpack to put it in a separate lazy-loaded chunk.
const clickHandler = module {
export default function () {
console.log("Clicked!");
}
}
@nicolo-ribaudo exactly
Again, if you look at the READAME Bundling section I linked earlier, you’ll see why it works in simple situations, but not as a general solution for bundling.
Maybe it would be worth mentioning that one usecase could be a code splitting (eg. with webpack).