In order to demonstrate the subjective nature of this topic, I will present alternate viewpoints to basarat’s response LOL.
What is the most effective strategy for organizing JavaScript output files?
My personal preference is to have the output files stored in a separate directory. Similar to how other compiled languages operate, it makes sense to have distinct directories for source files and output files.
src
contains all .ts
files except for type definitions, which belong in typings
.
lib
houses server (nodejs) outputs.
dist
stores client (browser) outputs.
This setup makes it clear what has been generated when there is nothing else cluttering the directory.
Furthermore, as the codebase expands, it becomes simpler to create batch build scripts tailored for each directory.
Should generated files be excluded from version control?
The decision varies. The TypeScript team opts to version the generated files in the TSC repository, but only includes the Latest Known Good version.
- If the goal is for users to clone the repository and immediately run the code, then versioning the files is advisable.
- However, if the intention is for users to clone the repository, install dependencies, build, and then execute the code, omitting file versioning may be more suitable.
In cases where a package is intended for distribution through a package manager, it is typically unnecessary to version generated files.
When testing the application, is it preferable to keep the JS output alongside the TS files or in a separate tree?
The same principles apply as discussed above.