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

langium package cannot be tree-shaken well #1642

Closed
jindong-zhannng opened this issue Aug 23, 2024 · 1 comment · Fixed by #1643
Closed

langium package cannot be tree-shaken well #1642

jindong-zhannng opened this issue Aug 23, 2024 · 1 comment · Fixed by #1643
Milestone

Comments

@jindong-zhannng
Copy link
Contributor

Reproduction: https://github.com/jindong-zhannng/langium-bundle-test
Bundler: vite

There is only one import in main.ts (to simulate the case of generated/ast.ts):

import { AbstractAstReflection } from 'langium'

And class AbstractAstReflection also has zero dependency.

Expect: Bundle should only include AbstractAstReflection relevant code.
Actual:

image

(run npx vite-bundle-visualizer --open -o ./stats.html to generate report)

Obviously it includes lots of dead code like parser, validator and their dependencies. It brings the bundle size up to 174.67 kB (minified).

Idea

I tried to add "sideEffects": false to package.json. It significantly reduces the size to 1.27 kB and has a perfect report:

image

I'm not sure if it's suitable for langium and I also don't have a very good understanding of this setting. Just put it here for your reference.

@msujew
Copy link
Member

msujew commented Aug 23, 2024

Hey @jindong-zhannng,

thanks for the investigation. Since we actually don't feature any side effects, I've filed #1643. It will be released as part of 3.2 (hopefully next week).

@spoenemann spoenemann added this to the v3.2.0 milestone Sep 25, 2024
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

Successfully merging a pull request may close this issue.

3 participants