January 17, 2025
Package Your TSConfig
How to publish and share your TypeScript configuration between projects.
By Ross Robinojavascript / tsconfig / npm
Your project will need to contain at minimum a package.json and another .json file containing your shared TSConfig. I have one TSConfig that I use in library development with tsc and another in app development when using a bundler. I have also included a README.md and a LICENSE.md.
Here are a couple of helpful fields that make it easier to share your TSConfig between projects.
For more information on each of these options check out Matt Pocock’s TSConfig Cheat Sheet. See this repository for the latest version of my TSConfig files.
A TSConfig package can be published with minimal configuration. Specify the following fields in your package.json.
Replace @robino/tsconfig with the name of your package you will publish to npm. Replace the MIT license if you wish to use a different license.
I’ve specified that this TSConfig needs to use TypeScript 5.5 or later because I’m using the configDir feature.
Any dependencies specified will be installed alongside your package when it is installed. I find it helpful to install the types for Node.js since I use Node APIs in most of my projects. This will make it so you have types when importing modules like "node:fs" by just installing your package, and you will manage the version in a central location.
There is no need to specify the main, or exports fields, TypeScript will find the files referenced by the entire path.
When you are ready, publish your package to npm using the npm publish command or your preferred method.
Once you have published your package, you can use your configurations in another project by installing them as a development dependency. For example, to install my package:
Any TSConfig can extend another configuration by using the extends option. Any fields provided in addition to the extends options will override the extended configuration.
Thanks for reading!…