打包Node.js
SEA配置
- 创建sea-config.json文件
json
{
"main": "dist/bundle.min.js",
"output": "index.blob",
// 禁用单文件可执行文件的实验性功能警告
"disableExperimentalSEAWarning": true,
}- 使用esbuild把项目打包成一个js文件(有第三方依赖的必要操作)
sh
npx esbuild index.js --bundle --platform=node --minify --outfile=dist/bundle.min.js- v25.5.0以及之后的Node.js版本,可以直接用以下的命令代替下面的三步
sh
node --build-sea sea-config.json- 执行命令生成index.blob文件
sh
node --experimental-sea-config sea-config.json- 复制Node.js运行环境
sh
node -e "require('fs').copyFileSync(process.execPath, 'hello.exe')"- 使用postject工具将Blob注入到可执行文件中
sh
npx postject hello.exe NODE_SEA_BLOB index.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 --overwrite