Files
continuwuity/packages/website/server-esbuild.js
T

60 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-08-26 20:21:41 +01:00
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
import esbuild from "esbuild";
// https://github.com/evanw/esbuild/pull/2067
const ESM_REQUIRE_SHIM = `
await (async () => {
const { dirname } = await import("path");
const { fileURLToPath } = await import("url");
/**
* Shim entry-point related paths.
*/
if (typeof globalThis.__filename === "undefined") {
globalThis.__filename = fileURLToPath(import.meta.url);
}
if (typeof globalThis.__dirname === "undefined") {
globalThis.__dirname = dirname(globalThis.__filename);
}
/**
* Shim require if needed.
*/
if (typeof globalThis.require === "undefined") {
const { default: module } = await import("module");
globalThis.require = module.createRequire(import.meta.url);
}
})();
`;
const banner = {
"js": ESM_REQUIRE_SHIM
2024-08-26 22:05:38 +01:00
};
2024-08-26 20:21:41 +01:00
esbuild.build({
sourcemap: true, // Source map generation must be turned on
platform: "node", // Node.js platform
target: "node22.0", // Node.js version
entryPoints: ["./build/index.js"], // Entry point file
outdir: "./output", // Output directory
bundle: true, // Generate an external bundle
2024-09-10 01:30:51 +01:00
splitting: true, // Enable code splitting
2024-08-26 20:21:41 +01:00
format: "esm", // Output format
loader: {
2024-08-26 22:05:38 +01:00
".node": "copy",
2024-08-26 20:21:41 +01:00
},
alias: {
"perf_hooks": "node:perf_hooks",
},
banner,
plugins: [
// Put the Sentry esbuild plugin after all other plugins
sentryEsbuildPlugin({
org: "jade-ellis",
project: "jade-website-sveltekit",
authToken: process.env.SENTRY_AUTH_TOKEN,
sourcemaps: {
// Specify the directory containing build artifacts
assets: "./output/**",
}
2024-08-26 20:21:41 +01:00
}),
],
});