Move bundling server from Rollup to esbuild
Fixes all sentry/otel related issues in deploy. Requires require shim. No longer needs to extern resvg.
This commit is contained in:
parent
d9cfc4bd2f
commit
b0cfdeb61b
6 changed files with 644 additions and 126 deletions
|
|
@ -1 +1,2 @@
|
|||
podman build . -f packages/website/Dockerfile -t jade-website-frontend:latest; podman save --format oci-archive jade-website-frontend:latest | gzip | ssh core@176.126.240.240 -T "zcat > /opt/images/jade-website-frontend"
|
||||
podman build . -f packages/website/Dockerfile -t jade-website-frontend:latest;
|
||||
podman save --format oci-archive jade-website-frontend:latest | gzip | ssh core@176.126.240.240 -T "zcat > /opt/images/jade-website-frontend"
|
||||
|
|
@ -14,19 +14,10 @@ FROM base AS deps
|
|||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
||||
# RUN cd packages/website; --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
||||
FROM deps as build
|
||||
ENV NODE_OPTIONS="--max-old-space-size=4096"
|
||||
RUN cd packages/website; pnpm run build
|
||||
|
||||
RUN cd packages/website; pnpm exec rollup -c server-rollup.config.mjs
|
||||
# copy node_modules/ and other build files over
|
||||
FROM node:latest as deploy-deps
|
||||
ENV PNPM_HOME="/pnpm"
|
||||
ENV PATH="$PNPM_HOME:$PATH"
|
||||
ENV CI=1
|
||||
RUN corepack enable
|
||||
|
||||
COPY --from=base /app/packages/website/package.json ./package.json
|
||||
COPY --from=base /app/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --no-frozen-lockfile --prod
|
||||
RUN cd packages/website; node server-esbuild.js
|
||||
|
||||
FROM node:alpine
|
||||
|
||||
|
|
@ -36,8 +27,6 @@ COPY --from=build /app/packages/website/output .
|
|||
COPY --from=build /app/packages/website/build/client ./client/
|
||||
COPY --from=build /app/packages/website/build/prerendered ./prerendered/
|
||||
COPY --from=base /app/packages/website/package.json ./package.json
|
||||
COPY --from=deploy-deps /app/node_modules/.pnpm ./node_modules/.pnpm/
|
||||
COPY --from=deploy-deps /app/packages/website/node_modules ./node_modules/
|
||||
|
||||
ENV NODE_ENV production
|
||||
EXPOSE 3000
|
||||
|
|
|
|||
|
|
@ -12,11 +12,8 @@
|
|||
"@bitmachina/highlighter": "1.0.0-alpha.6",
|
||||
"@fontsource/fira-mono": "^5.0.14",
|
||||
"@json-feed-types/1_1": "^1.0.2",
|
||||
"@rollup/plugin-commonjs": "^25.0.8",
|
||||
"@rollup/plugin-json": "^6.1.0",
|
||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||
"@rollup/pluginutils": "^5.1.0",
|
||||
"@sentry/rollup-plugin": "^2.22.2",
|
||||
"@sentry/esbuild-plugin": "^2.22.2",
|
||||
"@sveltejs/adapter-auto": "^3.2.4",
|
||||
"@sveltejs/adapter-node": "^5.2.2",
|
||||
"@sveltejs/kit": "^2.5.24",
|
||||
|
|
@ -25,6 +22,7 @@
|
|||
"@types/node": "^20.16.1",
|
||||
"@types/polka": "^0.5.7",
|
||||
"@types/sharedworker": "^0.0.115",
|
||||
"esbuild": "^0.23.1",
|
||||
"github-slugger": "^2.0.0",
|
||||
"glob": "^10.4.5",
|
||||
"hast-util-to-string": "^3.0.0",
|
||||
|
|
@ -65,6 +63,7 @@
|
|||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@babel/preset-typescript": "^7.24.7",
|
||||
"@codemirror/commands": "^6.6.0",
|
||||
"@codemirror/lang-javascript": "^6.2.2",
|
||||
"@codemirror/language": "^6.10.2",
|
||||
|
|
|
|||
55
packages/website/server-esbuild.js
Normal file
55
packages/website/server-esbuild.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
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
|
||||
};
|
||||
|
||||
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
|
||||
format: "esm", // Output format
|
||||
loader: {
|
||||
".node": "file",
|
||||
},
|
||||
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,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// rollup.config.mjs
|
||||
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import json from "@rollup/plugin-json";
|
||||
import { sentryRollupPlugin } from "@sentry/rollup-plugin";
|
||||
|
||||
export default {
|
||||
input: 'build/index.js',
|
||||
output: {
|
||||
dir: "output",
|
||||
format: 'esm',
|
||||
sourcemap: true,
|
||||
},
|
||||
// external: id => id.startsWith("@resvg/resvg-js-"),
|
||||
external: ["@resvg/resvg-js"],
|
||||
plugins: [
|
||||
nodeResolve(), json(), commonjs(),
|
||||
sentryRollupPlugin({
|
||||
org: "jade-ellis",
|
||||
project: "jade-website-sveltekit",
|
||||
authToken: process.env.SENTRY_AUTH_TOKEN,
|
||||
}),
|
||||
]
|
||||
};
|
||||
666
pnpm-lock.yaml
generated
666
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue