Skip to content

Commit

Permalink
feat: build for ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
svedova committed Jan 13, 2023
1 parent b5d4021 commit 01704b5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "npm run build:spa && npm run build:ssg",
"build:spa": "tsc && vite build",
"build:ssg": "tsc && SSG=true node --loader ts-node/esm ./src/vite-server.ts",
"build:ssr": "tsc && vite build -c vite.config.ssr.ts",
"preview": "vite preview"
},
"dependencies": {
Expand Down
41 changes: 41 additions & 0 deletions vite.config.ssr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { defineConfig } from "vite";
import path from "node:path";
import react from "@vitejs/plugin-react";
import pj from "./package.json";

process.env.NODE_ENV = "production";

// https://vitejs.dev/config/
export default defineConfig({
ssr: {
noExternal: Object.keys(pj.dependencies || {}).concat(
Object.keys(pj.devDependencies || {})
),
},
resolve: {
alias: [
{
find: /^~/,
replacement: path.resolve(__dirname, "src"),
},
],
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"],
},
build: {
ssr: true,
minify: false,
rollupOptions: {
preserveEntrySignatures: "strict",
input: { server: "src/entry-server.tsx" },
output: {
dir: ".stormkit/server",
format: "esm",
entryFileNames: "[name].mjs",
preserveModules: true,
preserveModulesRoot: "src",
exports: "named",
},
},
},
plugins: [react()],
});

0 comments on commit 01704b5

Please sign in to comment.