Replies: 3 comments 2 replies
-
If you run If you're not using Vite, you can add If you're using Vite you can set |
Beta Was this translation helpful? Give feedback.
-
If using Vite I've found the following useful to bundle the SSR build to avoid deploying node_modules, import { vitePlugin as remix } from "@remix-run/dev";
import { builtinModules } from "node:module";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [ remix() ],
ssr: {
// Bundle everything except the builtin node modules.
// https://github.com/vitejs/vite/issues/7821
external: [...builtinModules, ...builtinModules.map((m) => `node:${m}`)],
noExternal: process.env.NODE_ENV === "production" ? [/.*/] : [],
},
}); |
Beta Was this translation helpful? Give feedback.
-
any update? Can I bundle all server part to a single server.js file, and can run I have try a lot:
import { createRequestHandler } from "@remix-run/express";
import { installGlobals } from "@remix-run/node";
import compression from "compression";
import express from "express";
import morgan from "morgan";
installGlobals();
const remixHandler = createRequestHandler({
build: await import("./build/server/index.js"),
});
const app = express();
app.use(compression());
app.disable("x-powered-by");
app.use("/assets",express.static("build/client/assets", { immutable: true, maxAge: "1y" }));
app.use(express.static("build/client", { maxAge: "1h" }));
app.use(morgan("tiny"));
app.all("*", remixHandler);
const port = process.env.PORT || 3000;
app.listen(port, () =>
console.log(`Express server listening at http://localhost:${port}`),
);
import { vitePlugin as remix } from "@remix-run/dev";
import { installGlobals } from "@remix-run/node";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import { builtinModules } from "node:module";
installGlobals();
export default defineConfig({
plugins: [remix(), tsconfigPaths()],
server: { port: 3000 },
ssr: {
external: [...builtinModules, ...builtinModules.map((m) => `node:${m}`)],
noExternal: process.env.NODE_ENV === "production" ? [/.*/] : [],
},
});
import { defineConfig } from "tsup";
export default defineConfig({
entry: ["server.js"],
outDir: "dist",
target: "esnext",
format: "esm",
clean: true,
noExternal: [/(.*)/],
env: { NODE_ENV: "production" },
});
node dist/server.js but failed:
|
Beta Was this translation helpful? Give feedback.
-
Now when I build prod docker image, I just copy node_modules, the docker image size is very large. so can I pack node_modules to a bundle to reduce size?
Beta Was this translation helpful? Give feedback.
All reactions