Skip to main content

如何与 pkg 一起使用

¥How to use with pkg

客户端文件不会自动包含为资源,你需要手动指定它们:

¥The client files are not automatically included as assets, you need to manually specify them:

index.js

const { Server } = require("socket.io");

const io = new Server();

io.on("connection", (socket) => {
// ...
});

io.listen(3000);
caution

目前不支持 ES 模块。更多信息请点击这里:https://github.com/vercel/pkg/issues/1291

¥ES modules are not currently supported. More information here: https://github.com/vercel/pkg/issues/1291

pkg.json

{
"assets": "node_modules/socket.io/client-dist/*.js"
}

然后运行:

¥And then run:

$ pkg -c pkg.json -t node14-linux index.js

瞧!

¥And voilà!