Configuring TypeScript 16 exercises
Problem

Bundle Your Code for Library Use

In this exercise, you'll learn how to configure TypeScript for bundling our code for use in a library setting or publishing on NPM.

Inside of the tsconfig.json file are several configuration options to start with:


{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",

Loading exercise

Transcript

00:00 In this exercise, we're going to talk about how you can bundle your code for use in a library setting or for publishing on NPM. We have here a outdir, which is dist, which basically means we're going to be whatever we compile inside our source directory here is going to end up in the dist folder here.

00:19 And we also have rootdir added here, so root directory, which is being specified as source, which means that everything inside source is going to be compiled. And we also have include source, meaning that all of that stuff is going to be put in. But what we want is for each of these .js files, when they're bundled or when they're transpiled,

00:38 we also want an accompanying .d.ts file to be added to describe those files. Because currently, anyone using our code here, let's say they download it from NPM, they won't be able to use it in TypeScript, which is really weird considering that we've written it in TypeScript.

00:55 So your job is to work out how to configure this tsconfig.json file to build or create declaration files whenever it runs. We've got module node next, module resolution node next, and no emit is set to false, so everything should all be working.

01:11 It's just we need an extra little config option to make sure that declaration files are created when we run TSC. Good luck.