Skip to content

Commit 7eea5b7

Browse files
Add filter to esbuild plugin to scope entrypoint (#330)
* feat: add filter to esbuild plugin to scope entrypoint * feat: make entrypointFilter as a list of entrypoint
1 parent af977bd commit 7eea5b7

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

demo/client/build.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async function build(entryPoints, { env, output, extract, mockWebpackRequire })
1616
target: "app",
1717
mockWebpackRequire,
1818
bootstrapOutput,
19+
entrypoints: ["SinglePageRSC.re.js", "DummyRouterRSC.re.js", "NestedRouterRSC.re.js"],
1920
}),
2021
);
2122
}

packages/esbuild-plugin/plugin.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ async function generateBootstrapFile(output, content) {
2222
}
2323
}
2424

25+
function escapeRegex(string) {
26+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
27+
}
28+
2529
export default function plugin(config) {
30+
const entrypointFilter = new RegExp(config.entrypoints.map(escapeRegex).join("|"));
31+
2632
return {
2733
name: "extract-client-components",
2834
setup(build) {
@@ -59,7 +65,7 @@ export default function plugin(config) {
5965
}
6066
});
6167

62-
build.onResolve({ filter: /.*/ }, (args) => {
68+
build.onResolve({ filter: entrypointFilter }, (args) => {
6369
const isEntryPoint = args.kind === "entry-point";
6470

6571
if (isEntryPoint) {
@@ -71,7 +77,7 @@ export default function plugin(config) {
7177
return null;
7278
});
7379

74-
build.onLoad({ filter: /.*/, namespace: "entrypoint" }, async (args) => {
80+
build.onLoad({ filter: entrypointFilter, namespace: "entrypoint" }, async (args) => {
7581
const filePath = args.path.replace(/^entrypoint:/, "");
7682
const entryPointContents = await Fs.readFile(filePath, "utf8");
7783
const relativeBootstrapOutput = Path.relative(

0 commit comments

Comments
 (0)