【问题标题】:Publishing typescript package without ts files?发布没有 ts 文件的打字稿包?
【发布时间】:2016-12-05 04:03:34
【问题描述】:

我有一个要发布的打字稿项目,我在一个名为 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",
...

【问题讨论】:

    标签: typescript typescript2.0 tsconfig


    【解决方案1】:

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

    *.ts
    !*.d.ts
    

    更多关于 npmignore 的信息你可以找到here

    【讨论】:

    • 感谢您的回复所以我创建了这样的 .npmignore:.ts !.d.ts build declaration !*.log 但它不包括构建和声明已发布包中的目录
    • @user4092086 那么它们很可能在您的 gitignore 文件中。 .npmignore 只是从 .gitignore 扩展列表
    • hmm 试图从 .gitignore 中删除它们并没有再次起作用,尽管 .npmignore 应该覆盖 .gitignore
    • 对不起,我在 .npmignore 中犯了错误,我有构建声明而不是 !build 和 !declaration
    猜你喜欢
    • 1970-01-01
    • 2016-07-29
    • 2018-12-10
    • 2019-12-07
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 2015-02-13
    • 2017-08-31
    相关资源
    最近更新 更多