esbuild-plugins icon indicating copy to clipboard operation
esbuild-plugins copied to clipboard

feat: Allow customized filter to be passed from external source

Open vctqs1 opened this issue 1 year ago • 2 comments

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.

vctqs1 avatar May 31 '23 08:05 vctqs1