`langium` package cannot be tree-shaken well
Closed this issue · 1 comments
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:
(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:
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.
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).