Browse Source

🔧 chore(build): 优化构建配置

- 移除package.json中冗余的build:api命令
- 为build:client和build:server命令添加NODE_ENV和mode参数
- 在vite.config.ts中添加构建配置,指定客户端入口文件
- 修复package.json中dev:mini命令的格式问题
yourname 4 months ago
parent
commit
25966d41a3
2 changed files with 16 additions and 4 deletions
  1. 4 4
      package.json
  2. 12 0
      vite.config.ts

+ 4 - 4
package.json

@@ -5,10 +5,10 @@
   "scripts": {
     "dev": "concurrently \"pnpm run dev:mini\" \"pnpm run dev:web\" ",
     "dev:web": "PORT=8080 node server",
-    "dev:mini": "cd mini && pnpm run dev:h5",
-    "build": "npm run build:client && npm run build:server && npm run build:api",
-    "build:client": "vite build --outDir dist/client --manifest",
-    "build:server": "vite build --ssr src/server/index.tsx --outDir dist/server",
+    "dev:mini": "cd mini && pnpm run dev:h5", 
+    "build": "npm run build:client && npm run build:server",
+    "build:client": "cross-env NODE_ENV=production vite build --outDir dist/client --manifest --mode production", 
+    "build:server": "cross-env NODE_ENV=production vite build --ssr src/server/index.tsx --outDir dist/server --mode production",
     "build:api": "vite build --ssr src/server/api.ts --outDir dist/api",
     "start": "PORT=8080 cross-env NODE_ENV=production node server"
   },

+ 12 - 0
vite.config.ts

@@ -37,4 +37,16 @@ export default defineConfig({
       '@': '/src',
     },
   },
+  // 构建配置
+  build: {
+    // 对于SSR,我们不需要默认的index.html入口
+    // 为客户端构建指定JS入口文件
+    rollupOptions: {
+      input: {
+        // 这里指定你的客户端入口JS文件
+        main: 'src/client/index.tsx',
+        styles: 'src/style.css',
+      },
+    },
+  },
 })