Skip to content

Commit b396c8c

Browse files
committed
Revert "simplify build"
This reverts commit 9f46666.
1 parent 2fee564 commit b396c8c

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

build.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Glob, fileURLToPath, pathToFileURL, type JavaScriptLoader } from "bun";
1+
import { Glob, fileURLToPath, pathToFileURL } from "bun";
22
import { basename, join, relative } from "node:path";
33

44
function escapeRegExp(string: string) {
@@ -52,40 +52,40 @@ export async function build({
5252
name: "bun-react-ssr",
5353
target: "browser",
5454
setup(build) {
55-
// workaround for https://github.com/oven-sh/bun/issues/12892
56-
const trimmer = new Bun.Transpiler({
57-
deadCodeElimination: true,
58-
treeShaking: true,
59-
exports: { eliminate: ["getServerSideProps"] },
60-
trimUnusedImports: true,
61-
});
6255
build.onLoad(
6356
{
6457
filter: new RegExp(
6558
"^" + escapeRegExp(absPageDir) + "/.*" + "\\.ts[x]$"
6659
),
6760
},
6861
async ({ path, loader }) => {
69-
const contents = await Bun.file(path).text();
70-
const tsloader = new Bun.Transpiler({
71-
loader: loader as JavaScriptLoader,
72-
autoImportJSX: true,
73-
});
74-
if (
75-
!tsloader.scan(contents).exports.includes("getServerSideProps")
76-
) {
77-
return { contents, loader };
78-
}
79-
const js = await tsloader.transform(
80-
await Bun.file(path).text(),
81-
loader as JavaScriptLoader
82-
);
62+
const search = new URLSearchParams();
63+
search.append("client", "1");
64+
search.append("loader", loader);
8365
return {
84-
contents: await trimmer.transform(js, "js"),
85-
loader: "js",
66+
contents:
67+
"export { default } from " +
68+
JSON.stringify("./" + basename(path) + "?client"),
69+
loader: "ts",
8670
};
8771
}
8872
);
73+
build.onResolve(
74+
{ filter: /\.ts[x]\?client$/ },
75+
async ({ importer, path }) => {
76+
const url = pathToFileURL(importer);
77+
return {
78+
path: fileURLToPath(new URL(path, url)),
79+
namespace: "client",
80+
};
81+
}
82+
);
83+
build.onLoad(
84+
{ namespace: "client", filter: /\.ts[x]$/ },
85+
async ({ path, loader }) => {
86+
return { contents: await Bun.file(path).text(), loader };
87+
}
88+
);
8989
},
9090
},
9191
],

0 commit comments

Comments
 (0)