This is an opinionated dev container for TypeScript. You can use it for all kinds of projects, including micro services, frontends, etc. The dev container is designed to be used on hosts running MacOS, Linux or Windows.
Note that this is a full-time dev container. VS Code remotely connects to the dev container and all commands are executed inside of the dev container. Any terminals you open inside of VS Code are terminals of the dev container. This dev container is not used in a model where it lives only for the duration of one command.
If you are at the repository in github, click the green button with Use this template
to create a new repository with the code of this repository as a starting position.
After you created your new repository, change the published (aka exposed) port number to a number that you don't use that. Only then create the dev container locally by reopening it with VS Code or by using the following command in a terminal at the root of the repository:
docker-compose -f .devcontainer/docker-compose.yml build
Once the dev container is running, create your TypeScript project just like you'd do without the dev container. The difference is, that apart from the prerequisites listed below, you do not need to install any other software.
You need the following software in order to use this container:
- VS Code
- VS Code extension "Remote Development"
- git client
- Docker Desktop (MacOS, Windows) or docker engine (Linux)
All other tools, e.g. TypeScript, will be available inside the dev container.
As this container is opinionated, it is maintained with the following concepts in mind:
- Container to be used full-time, i.e., not just while a command is executed
- Designed for VS Code but can be used with other IDEs as well
- Trunk-based development. If you have branches other than
main
the settings should still work. git pull
does rebase- Auto-forwarding of ports (automatic mapping) by VS Code is switched off. It's better to fail fast. You need to understand how port mapping works. Consult with the Docker documentation for more details.
- Use specific versions for node, npm, typescript and similar dependencies to reduce variability.
- Use latest stable releases if possible but no pre-release, beta, previews, etc.
- Minimize the number of prerequisites for getting started. All other tools should be specified in the dev container.
- TypeScript strings use single quotes
- Files are formatted on save
- Tab size is 3
This repository also contains the complete source code for these two articles:
-
"Creating a Dev Container for TypeScript and VS Code - Part 1"
-
"Creating a Dev Container for TypeScript and VS Code - Part 2"
The code for part 1 is in branch "part-1".
Equally, the code for part 2 is in branch "part-2".