Packaging a Typescript project into an executable

≡放荡痞女 提交于 2020-05-17 05:04:26

问题


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).

  1. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!