An esbuild plugin to help you compute and mark external modules manually.
- Excludes
dependencies
andpeerDependencies
frompackage.json
. - Adds custom loader
with { external: "./replacement.js" }
. - Automatically externalizes imports with pattern matching.
import external from '@hyrious/esbuild-plugin-external'
await esbuild.build({
entryPoints: ['src/index.ts', 'src/cli.ts'],
bundle: true,
format: 'esm',
platform: 'node',
packages: 'bundle',
plugins: [external()]
}).catch(() => process.exit(1))
external({
package: true,
filter: /\.ts$/,
auto: [{ filter: /\.js$/ }],
})
-
package: Automatically mark dependencies and peer dependencies from package.json. This is enabled by default.
-
filter: Filter in files to be enhanced to use import attribute
with { external: "replace" }
. This is disabled by default, you need to pass in a regex to make it work. Example:import * as mod from '../foo' with { external: "./foo.js" } // will be bundled into => import * as mod from './foo.js'
-
auto: Filter in paths to be externalized and perform a simple replacement to strip leading
'../'
s. This is disabled by default, you need to pass in a config to make it work. Example:// auto: [{ filter: /\.js$/ }] import * as mod from './index.js' // will be marked external import * as mod from '../foo.js' // will be externalized as './foo.js'
MIT @ hyrious