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

Feature request: Import type / types in Metadata.outputs[*].imports[*] #655

Closed
ggoodman opened this issue Jan 7, 2021 · 4 comments
Closed

Comments

@ggoodman
Copy link

ggoodman commented Jan 7, 2021

Use-case

Reading the build metadata of a code-split front-end and generating <link rel="modulepreload" /> tags for synchronous imports (or at least prioritizing such over dynamic imports).

Challenge

The challenge I've seen is understanding the type of imports surfaced in Metadata. I would like to be able to traverse the chunk dependency graph and generate appropriate preloads but would like to exclude dynamic imports from these. The metadata produced by esbuild doesn't include enough information to make the distinction between dynamic and synchronous imports.

@evanw
Copy link
Owner

evanw commented Jan 13, 2021

Thanks for filing this. I've considered including this in the past. This is why the imports are objects instead of strings (so I can add additional properties). I was mainly just waiting for a use case. So I can add this.

@evanw
Copy link
Owner

evanw commented Jan 13, 2021

Actually it looks like dynamic imports are already not included in the list of imports for an output chunk. This is a bug that should be fixed, but for now it should give you what you need. Can you confirm that dynamic imports in chunks are omitted for you too?

@ggoodman
Copy link
Author

@evanw, you know what? You're probably right and I never even noticed. This actually suits my use-case quite well because I'm only interested in generating <link rel="modulepreload" href=""> tags for synchronous imports. As a result, this doesn't impact me much.

I hope that if / when this 'bug' is fixed, we'll also have the ability to filter on sync vs async chunk dependencies.

@evanw evanw closed this as completed in 4c997fc Jan 14, 2021
@evanw
Copy link
Owner

evanw commented Jan 14, 2021

That bug hasn't been fixed yet but in the next release you'll be able to filter by obj.kind === 'import-statement' (or by obj.kind !== 'dynamic-import'). I'll try to fix that during the upcoming code splitting rewrite.

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.

2 participants