Search code examples
typescripttypescript2.0tsconfig

Publishing typescript package without ts files?


I have a typescript project that I want to publish it, I generate all the js files in a directory called build and all declaration files in a directory called declaration, I don't want to include .ts files in my published version I was wonder how can I do this without using gulp?

here is my tsconfig.json

{
    "compilerOptions": {
       "target": "es6",
        "lib": ["es6", "dom"],
        "types": ["reflect-metadata"],
        "module": "commonjs",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "outDir": "build",
        "declarationDir": "declaration"
    },
    "exclude": [
        "node_modules"
    ]
}

and my package.json:

{
  "name": "data-layer",
  "version": "1.1.4",
  "description": "data access layer",
  "main": "./build/index.js",
  "types": "./declaration/index.d.ts",
...

Solution

  • Just use .npmignore file where you tell to ignore all files that are .ts but not .d.ts

    *.ts
    !*.d.ts
    

    More information on npmignore you can find here