.npmignore - 忽略所有 *.ts 文件但不包括 *.d.ts

.npmignore - Ignore all *.ts files but not *.d.ts

我正在寻找一种在我发布到 NPM 时忽略项目中所有 .ts 文件的好方法,我可以通过将以下内容添加到我的 .npmignore 文件中来实现:

*.ts

但是等等..实际上我想在我的项目中保留所有 .d.ts 文件,当我发布...

我可以在我的 .npmignore 文件中添加什么来保留所有 .d.ts 个文件但忽略所有 .ts 个文件?

我假设我必须使用某种形式的正则表达式来忽略所有以 .ts 结尾但不以 .d.ts

结尾的文件

因此 JS 正则表达式可能如下所示:

*.\.[^d]\.ts

上述正则表达式的意思是匹配任何以 .ts 结尾但不以 .d.ts

结尾的内容

当然,我们仍然坚持使用我认为 OS 等

所使用的不太强大的正则表达式。

.npmignore 的文档中指出:

.npmignore files follow the same pattern rules as .gitignore files:

在这种情况下,您可以使用 ! 否定 .npmignore 中的 .d.ts 文件。例如,在您的 .npmignore 中,您只需:

# ignore the .ts files
*.ts

# include the .d.ts files
!*.d.ts