Deprecated: This plugin is unnecessary now because it has been supported by esbuild natively from v0.19.0.
Dynamic import variables support for esbuild
# pnpm
pnpm add -D esbuild-plugin-dynamic-import
# yarn
yarn add -D esbuild-plugin-dynamic-import
# npm
npm i -D esbuild-plugin-dynamic-importimport { dynamicImport } from 'esbuild-plugin-dynamic-import'
esbuild.build({
  plugins: [
    dynamicImport({
      // filter: // optional, default: /\.([cm]?[jt]s|[jt]sx)$/
      // ignore: // optional, default: /\bnode_modules\b/
      // loader: // optional, default: adjust with path extension
    }),
  ],
})const lazyImport = () => import(`./pages/${page}`)
// comments are allowed
const lazyImport = () =>
  import(
    /* comment1 */ // inline comment
    /**
     * multiline comment
     */
    `./pages/${
      page
      // inline comment
      /* comment2 */
    }`
  )The expressions are matched with RegExp instead of parsing as AST for performance reason, so you should only use it for simple cases as following:
- relative path required
 - template literal required
 - no 
)in the()pair - extensions are optional
 
Additionally, the built-in functionality will be available in esbuild soon (maybe): evanw/esbuild#2508 (comment)
| 1stG | RxTS | UnTS | 
|---|---|---|
| 1stG | RxTS | UnTS | 
|---|---|---|
Detailed changes for each release are documented in CHANGELOG.md.