0.1.0 • Published 1 year ago

esbuild-plugin-dynamic-import v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

esbuild-plugin-dynamic-import

GitHub Actions type-coverage npm GitHub Release

Conventional Commits Renovate enabled JavaScript Style Guide Code Style: Prettier changesets

Dynamic import variables support for esbuild

TOC

Usage

Install

# pnpm
pnpm add -D esbuild-plugin-dynamic-import

# yarn
yarn add -D esbuild-plugin-dynamic-import

# npm
npm i -D esbuild-plugin-dynamic-import

API

import { 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
    }),
  ],
})

Usage

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:

  1. relative path required
  2. template literal required
  3. no ) in the () pair
  4. extensions are optional

Additionally, the built-in functionality will be available in esbuild soon (maybe): https://github.com/evanw/esbuild/pull/2508#issue-1356677535

Sponsors

1stGRxTSUnTS
1stG Open Collective backers and sponsorsRxTS Open Collective backers and sponsorsUnTS Open Collective backers and sponsors

Backers

Backers

1stGRxTSUnTS
1stG Open Collective backers and sponsorsRxTS Open Collective backers and sponsorsUnTS Open Collective backers and sponsors

Changelog

Detailed changes for each release are documented in CHANGELOG.md.

License

MIT © JounQin@1stG.me

0.1.0

1 year ago

0.0.1

1 year ago