Skip to content

Bundle glob-based dynamic imports #2515

@Cephyric-gh

Description

@Cephyric-gh

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions