typescript - 发布没有 ts 文件的 typescript 包?

标签 typescript typescript2.0 tsconfig

我有一个要发布的 typescript 项目,我在名为 build 的目录中生成所有 js 文件,并在名为 declaration 的目录中生成所有声明文件,我不想在发布的版本中包含 .ts 文件 我想知道如何在不使用 gulp 的情况下做到这一点?

这是我的 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"
    ]
}

和我的 package.json:

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

最佳答案

只需使用 .npmignore 文件,告诉您忽略所有 .ts 但不是 .d.ts 的文件

*.ts
!*.d.ts

有关 npmignore 的更多信息,您可以找到 here

关于typescript - 发布没有 ts 文件的 typescript 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40962867/

相关文章:

typescript - 从 MS Graph API 获取用户照片并显示图像

angular - 类型 ClassB 中的属性 x 不可分配给基类型 ClassA 中的相同属性

angularjs - Angular 2动态生成的表单组

typescript - 万一使用泛型 TypeScript 的主要原因是什么?

javascript - 防止 Typescript 编译器检查整个类以节省时间?

javascript - `tsc` 命令是否接受 .d.ts 文件?

html - ngIf 用于关闭/打开标签

reactjs - 条件 Prop 的 TypeScript 实用程序类型(基于类型中其他属性的输入值)

typescript - 检查属性是否用特定注释装饰 - Typescript

node.js - 无法在 typescript 构建中包含 .key 文件