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

Bundle glob-based dynamic imports #2515

Closed
Cephyric-gh opened this issue Sep 2, 2022 · 3 comments
Closed

Bundle glob-based dynamic imports #2515

Cephyric-gh opened this issue Sep 2, 2022 · 3 comments

Comments

@Cephyric-gh
Copy link

In 1 of our projects we dynamically import files at runtime based on what the user has requested. Previously when we were using webpack to build the project it would automatically detect those import lines and include all the files that matched the base of the import in the bundle out of the box, however I cannot get this to work with esbuild. An example of 1 of the import lines is as follows:

let ctor: {default: {new(event: IdentifiedEvent, ides: Record<string, string>): Bases}};

switch (method) {
    case HttpMethod.GET:
        ctor = await import(`../actions/native/${provider}/get/${version}/${path}`);
        break;
    case HttpMethod.POST:
        ctor = await import(`../actions/native/${provider}/post/${version}/${path}`);
        break;
    case HttpMethod.PUT:
        ctor = await import(`../actions/native/${provider}/put/${version}/${path}`);
        break;
    case HttpMethod.PATCH:
        ctor = await import(`../actions/native/${provider}/patch/${version}/${path}`);
        break;
    case HttpMethod.DELETE:
        ctor = await import(`../actions/native/${provider}/delete/${version}/${path}`);
        break;
}

Is there a way I can make esbuild detect these imports and include the files in the bundle similarly to webpack?

@Cephyric-gh
Copy link
Author

Further digging lead me to #56, which shows that it's in fact a limitation of esbuild that is not intended to be resolved. Unfortunate, but will look at the workarounds suggested in that issue.

@evanw
Copy link
Owner

evanw commented Sep 2, 2022

That's a very old issue. I'm now working on doing a form of this: #2508

@Cephyric-gh
Copy link
Author

Oh that's really good to hear (and very useful timing!), I will subscribe to that PR and await for a version to be released with this change for now then and continue with other things (still got a whole bunch of other things to migrate over for this specific project anyway, so the old webpack builder will suffice until that new change is released)

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

2 participants