问题
Is there a tool to achieve the above easily?
As I was looking for a while and couldn't find any, I used for now node to achieve the above. I'm publishing what I did, hoping someone will find it useful.
1.Compile Typescript project into node (according to this). I personally used tsc.
Note: when using webpack I came across some problems with net and fs. Adding the following to Webpack.config.js helped:
node: {
net: 'empty',
fs: 'empty'
}
(References here and here)
2.After compiling the project, I ran it using node (for validation only).
- To create an exe file from node project, I used pkg.
The tsconfig.json I used is:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./dist/server",
"strict": true,
"sourceMap": true,
"typeRoots": [
"node_modules/@types", "./typings"
]},
"exclude": [
"dist",
"node_modules"
]
}
And added the following to the package.json (reference)
"build-ts": "tsc --project ./tsconfig.json"
来源:https://stackoverflow.com/questions/56737410/packaging-a-typescript-project-into-an-executable