How can i add dynamic import in my bundle with esbuild?

2.1k views Asked by At

I have module with dynamic import

index.mjs

...
const components = [
 'fer-dialog',
 'welcome-description',
 'welcome-diagram',
 'welcome-feedback',
 'welcome-logo',
]

 for (let i = 0; i < components.length; ++i) {         
   import(`${pathname}/component/${components[i]}/index.mjs`)
 }
....

My esbuild config

...
const buildParams = {
  entryPoints: ["./index.mjs"],
  outfile: '../build/index.mjs',
  format: "esm",
  target: "es2022",
  loader: {  '.css': 'copy', '.data': 'base64' , ".js": "jsx",".ttf":"base64", ".json": "copy", ".png": "file", ".jpeg": "file", ".jpg": "file", ".svg": "dataurl", ".woff": "file" },
  color: true,
  minify: true,
  bundle: true,
  sourcemap: true,
  mainFields : [ 'module' , 'main' ],
  define,
  logLevel: "error",
  external: ["*.gif"]
...

The bundle does not include dynamic imports.

Is there a plugin or possibility to add dynamic imports to the bundle ?

0

There are 0 answers