esbuild-plugins
esbuild-plugins copied to clipboard
feat: Allow customized filter to be passed from external source
In my use case, I am utilizing esbuild in development mode and would like to externalize for the react
and react-dom
packages. However, I do not want to externalize the nested packages like react/jsx-runtime
and react/jsx-dev-runtime.
plugins: [EsmExternals({ externals: ['react', 'react-dom'] })],
Currently, the makeFilter
function defaults to a positive match for all cases, including react/jsx-runtime
and react/jsx-dev-runtime
. We have a corresponding test case available here.
To address this, I have introduced the ability to pass externals as regrex and customize by myself instead, allowing for customization.
const externalRegExp = new RegExp("^(" + ["react", "react-dom"].join("|") + ")$")
// this will make all react and react-dom packages externals, but not react/abc or react-dom/abc
build({
plugins: [EsmExternals({ externals: externalRegExp })],
})
This pull request aims to implement this enhancement and improve the flexibility of the EsmExternalsPlugin
.
Thank you for your consideration.