npm package using typescript best practice

Topics: General
Nov 2, 2012 at 5:59 PM

What would be the recommended way when creating an npm package with typescript (ts) files, to package the module:

  1. Only package ts files and compile during install using typescript's tsc.
  2. Only package js files and precompile (ts --> js) before packaging.
  3. Package both ts and js files and compile before packaging.





Nov 2, 2012 at 7:46 PM

Like other packages in other languages (like CoffeScript), put your ts files in your package, add a dev dependency and main entry to your build system.

Nov 2, 2012 at 8:12 PM

I'm not sure which option you're referring to (or is it a new one?)


Dec 29, 2013 at 1:12 AM
The npm documentation actually contains a section about this:
For build steps that are not platform-specific, such as compiling CoffeeScript or other languages to JavaScript, use the prepublish script to do this, and make the required package a devDependency.
So the answer to your question would be either #2 or #3, depending on whether or not you expect package consumers to utilize the TypeScript files. Personally I think #2 makes the most sense, with the caveat that .d.ts definition files should also be included (these can be generated automatically using grunt-ts).