Loading
Build a TypeScript Project From Scratch Tutorial (19 exercises)
Lesson

Prep Library for Production

In this lesson, you will prep your code for publishing to npm.

Resources

The following resources provide more information for this lesson:

  • Read more about .npmignore
  • [microbundle](<https://github.com/developit/microbundle>)
  • TypeScript Handbook: Module Output Options
    • [target](<https://www.typescriptlang.org/tsconfig#target>) which determines which JS features are downleveled (converted to run in older JavaScript runtimes) and which are left intact
    • [module](<https://www.typescriptlang.org/tsconfig#module>) which determines what code is used for modules to interact with each other

Transcript

[0:00] [0: 00] The first thing you need to do is get our package.json in order for publishing. Here, you can see a diff of the changes I've made in the package.json.
[0:07] [0: 07] The most important ones that I want to point out are name and version. We're going to publishing this under your GitHub username, because streak-counter is probably taken. I have -2 in mind, because I've already done this, and version, start of at ..1.

[0:20] [0: 20] We'll be using a tool called Microbundle to bundle our project for publishing on nmp. First, install it as a dev dependency. From Microbundle, we'll make the following changes. I'm not going to go through each one, but a lot of these will just ensure that our library works in a handful of different environments and different versions of JavaScript.

[0:42] [0: 42] Next, we'll be making changes to our tsconfig.json. I went ahead and removed all comments so you can see what we're working with before we make changes. As you can see, we've made a couple of changes which are just going to allow our project to be compiled correctly according to what Microbundle expects. You can refer to the TS handbook if you want to understand what each of these things do.

[1:05] [1: 05] The final thing we're going to do is create a .npmignore at the root of streak-counter, and we'll add two lines in here, _tests_ and .github. This tells npm, when you publish our package, don't bundle these files or, in this case, these directories.

[1:21] [1: 22] That's it for now. In the next video, we will actually publish this to npm.