اللغات المدعومة في الصفحة الحالية:

简体中文

Vite Plus 打包 Node + TS 项目为单文件可执行程序

NodeViteSEA
# Note

عدد الكلمات 1407

الوقت المستغرق تقريباً 6 minutes

الاثنين، 6 يوليو 2026 في 14:10:00 UTC
项目的依赖不能超出SEA支持范围,否则将打包失败: ✅ SEA 只能稳定支持“纯 JS + 可静态打包依赖” ❌ 一旦涉及 native addon / browser binary / runtime dynamic loader 就基本不可用

Vite 配置

参考:Vite官方文档

vite.config.ts
import { defineConfig } from 'vite-plus'

export default defineConfig({
  ssr: {
    // 依赖内部化,避免外部依赖
    noExternal: true,
  },
  build: {
    ssr: true,
    target: 'node26',
    rolldownOptions: {
      input: 'src/main.ts',
        output: {
          format: 'cjs',
          entryFileNames: 'main.cjs',
        },
    },
  },
})

Node SEA配置

参考:Node官方文档

sea-win.json
{
  "main": "dist/main.cjs",
  "output": "dist/webmonitor.exe",
  "disableExperimentalSEAWarning": true,
  "useCodeCache": false,
  "useSnapshot": false
}
package.json
{
  "type": "module",
  "scripts": {
    "dev": "node --env-file=.env src/main.ts",
    "build": "vp build",
    "build-win": "vp build && node --build-sea sea-win.json",
    "build-linux": "vp build && node --build-sea sea-linux.json",
  }
}

打包

pnpm build-win

© 2019-2026 Kaz. All rights reserved.