2

Is it possible to build a TS source into a single file, which would also contain node_modules imported packages' source?

That would be very helpful in a serverless project. I have done this before on a non-TS project but was using webpack (for another reason).

It seems this was briefly possible before but was due a bug https://github.com/Microsoft/TypeScript/issues/13414 ?

3
  • What did you try? Can you share your config? Commented Mar 13, 2019 at 11:28
  • I believe your approach is invalid. Node modules should not be bundled to compiled code but rather packed and sent together to serverless project. Why don't you use tools like "serverless" that will handle that for you? Commented Mar 13, 2019 at 11:30
  • @wookieb I do use serverless an am aware it does it for me. Why you say it should not be bundled together? I got better "performance" by uploading a single file and not having that process of separating needed node_modules Commented Mar 13, 2019 at 11:33

1 Answer 1

5

You will need to use a bundler such as webpack to bundle your compiled code and all your node_modules dependencies. The TypeScript compiler (tsc) just transforms TypeScript code into JavaScript, and won't deal with bundling.

Sign up to request clarification or add additional context in comments.

2 Comments

not true, tsc can do it with --out param. "tsc --out target.js source.ts"
That will build all of the TypeScript compiler output into a single file, but not the source code of your dependencies, which is what the author is asking for I believe.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.