0.1.0 • Published 1 year ago
esbuild-plugin-dynamic-import v0.1.0
esbuild-plugin-dynamic-import
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:
- 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): https://github.com/evanw/esbuild/pull/2508#issue-1356677535
Sponsors
1stG | RxTS | UnTS |
---|---|---|
Backers
1stG | RxTS | UnTS |
---|---|---|
Changelog
Detailed changes for each release are documented in CHANGELOG.md.