[Discussion] Consider generating sub-types into separate files as well
kevinresol opened this issue · 3 comments
// Main.hx
import Foo;
class Main {
static function main() {
trace(Bar);
dynamicImport(Foo -> trace(Foo);
}
}
// Foo.hx
class Foo() {}
class Bar() {}
The above code will not enjoy code splitting because of the generated static import for sub-type Bar
:
import {Bar} from './Foo';
Could this be improved by generating sub-types into separate files too? Are there any implications?
One of my use cases for genes is (eventually) publishing some generated js code. To have the best interop (and ease documentation) having the same structure is quite useful.
Your scenario I think is actually more of a limitation of javascript tree shaking. If the bundler was "smarter" it should be able to split these (but none do, I tested some similar things).
But, the way things currently work, it shouldn't be too hard to add a flag to force every type to get their own module, which would allow your use case too.
Another option is to produce a warning if you're using dynamicImport but a type from the same module is imported outside of the callback.
Information like that would be useful too 👍