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] add support for webpackInclude or similar #1750

Closed
goenning opened this issue Nov 7, 2021 · 2 comments
Closed

[Feature Request] add support for webpackInclude or similar #1750

goenning opened this issue Nov 7, 2021 · 2 comments

Comments

@goenning
Copy link

goenning commented Nov 7, 2021

When code splitting is not enabled, ESBuild will bundle all dynamic imports together, which is exactly what I want in my scenario. The issue I have is that I need to statically name all modules I want to bundle, while in webpack I can do this:

export const AsyncPage = (pageName: string) =>
      import(
        /* webpackInclude: /\.page.tsx$/ */
        /* webpackChunkName: "[request]" */
        `@fider/pages/${pageName}`
      )

Is there a similar feature in ESBuild? Essentially I want to bundle all *.page.tsx into a single bundle and later use § import(pageName).then(...).

Note: I'm using the output bundle for Server Side Rendering, so having all pages in single build is OK.


The current solution I have is to keep a static map of all pages, which I'm trying to avoid.

const pages: { [key: string]: any } = {
  "Home/Home.page": require(`./pages/Home/Home.page`),
  "ShowPost/ShowPost.page": require(`./pages/ShowPost/ShowPost.page`),
  "SignIn/SignIn.page": require(`./pages/SignIn/SignIn.page`),
  "SignUp/SignUp.page": require(`./pages/SignUp/SignUp.page`),
  "Legal/Legal.page": require(`./pages/Legal/Legal.page`),
  "DesignSystem/DesignSystem.page": require(`./pages/DesignSystem/DesignSystem.page`),
}

const component = pages[pageName].default
@hyrious
Copy link

hyrious commented Nov 7, 2021

There's a fork of esbuild by netlify team doing what you said, it provides an extra plugin api build.onDynamicImport to do so.

There's another cheap solution in vite, you can write a plugin to search for specific function call, and then rewrite it to a static map like what you have done.

@evanw
Copy link
Owner

evanw commented Nov 7, 2021

This issue is already a duplicate. Closing as a duplicate of #1240 and #700.

@evanw evanw closed this as completed Nov 7, 2021
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

3 participants