-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Astro pre-evaluates dynamic imports that prevents tree-shaking #6328
Description
What version of astro are you using?
2.0.14
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
It doesn't matter for this bug
Describe the Bug
All the dynamic imports and import.meta.glob imports are bundled in my production build, regardless of whether they are used on the page. I could resolve all the modules by myself when needed, but it's impossible due to this bug. For a more detailed description of the bug and why I need this feature, see vitejs/vite#12104.
Here is another reproduction of the bug: https://stackblitz.com/edit/github-b1xdf7?file=src%2Fpages%2Findex.astro. I also think that this feature would help a lot of projects to significantly reduce the size of a bundle.
Astro's official documentation:
You can also use import.meta.glob() itself in your Astro project. You may want to do this when:
- You don’t want to load each file immediately. import.meta.glob() can return functions that import the file content, rather than returning the content itself.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-b1xdf7-rajkhn?file=src%2Fpages%2Findex.astro
Participation
- I am willing to submit a pull request for this issue.