如何将 Typescript 项目打包成可执行文件?
因为我找了一段时间没有找到,所以我现在使用节点来实现上述目标。我正在发布我所做的,希望有人会发现它有用。
注意: 在使用 webpack 时遇到了 net 和 fs 的一些问题。 将以下内容添加到 Webpack.config.js 有帮助:
node: {
net: 'empty',
fs: 'empty'
}
编译项目后,我使用节点运行它(仅用于验证)。
为了从节点项目创建一个exe文件,我使用了pkg。
我用的tsconfig.json是:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./dist/server",
"strict": true,
"sourceMap": true,
"typeRoots": [
"node_modules/@types", "./typings"
]},
"exclude": [
"dist",
"node_modules"
]
}
并在 package.json 中添加以下内容(reference)
"build-ts": "tsc --project ./tsconfig.json"
尝试将其构建到 javascript 中,然后使用 https://github.com/vercel/pkg