Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal.js coming in way of TreeShaking #54

Open
damooo opened this issue Oct 7, 2019 · 6 comments
Open

internal.js coming in way of TreeShaking #54

damooo opened this issue Oct 7, 2019 · 6 comments

Comments

@damooo
Copy link
Contributor

damooo commented Oct 7, 2019

Hello guys,
Thanks for manifesto..

in latest commit, you created internal.ts as proxy for importing inside lib. now with this, bundlers like rollup cannot perform tree-shaking.
let's say we want to import only Canvas class into a project, without entire library, then as that imports exports from internal.js, and it inturn imports everything, then rollup bundles entire manifesto for one class. tree shaking is essential for smaller builds.
internal.js giving no other practical value than giving these inconviences and creating circular imports, etc.

@edsilv
Copy link
Member

edsilv commented Oct 7, 2019

@damooo
Copy link
Contributor Author

damooo commented Oct 7, 2019

this pattern may be good for applications, which are not depended by others.. but libraries require tree shaking. is circular imports for Type coercion?
same author noted in comments:

but to enable tree shaking, you could limit the pattern to those files affected by circular deps (since circulary dependend files will either both or not at all appear in the output). This does make the process more error prone though. But doing that can also be beneficial for code splitting and such.

This might potentially hurt code splitting indeed, the clue is to do it only for parts that are logically bound together (note that you can apply this pattern repeatedly to different parts of your code base!). If done properly, then it shouldn't affect the code splitting

@edsilv
Copy link
Member

edsilv commented Oct 7, 2019

Yeah I was thinking to maybe only limit it to the affected files. It's the top four here: https://github.com/IIIF-Commons/manifesto/blob/master/src/internal.ts
I'm traveling today, so if you wanted to do a PR that would be most welcome :-)

@edsilv
Copy link
Member

edsilv commented Oct 7, 2019

i.e leave the top four in internal, and remove the rest. The TS compiler will catch the import errors so it should just be a case of adding those back in. Also, index.ts will need to export them too.

@damooo
Copy link
Contributor Author

damooo commented Oct 8, 2019

I tried to do that.. but tests doesn't passed if we just include only those four in internal.ts.. every time it shows an error for a new module circular import like Thumbnail, Collection, etc.. if i add one by one it is showing remaining in errors, effectively i have to add back most of them to internal.ts. so i restrained from PR.

for size related matters, there is another issue opened #55 .

@stephenwf
Copy link
Member

@edsilv @damooo maybe wee need a couple of Types/Interfaces for those classes specifically, allow us to reference their properties without loading them in. I'm not sure exactly how this works, but you can do:

const something: import('./path/to/module').ExportName;

That way it won't actually bundle the module, instead just stripping out the types and ignoring it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants