【问题标题】:what is this rimraf argument --tsconfig about这个 rimraf 参数 --tsconfig 是关于什么的
【发布时间】:2021-11-30 20:40:21
【问题描述】:

我是 Node 新手,在这个 package.json for React Typescript 项目中,我了解 rimraf 做了什么,但 --tsconfig 最后在做什么?

当我运行 prebuild 脚本时,我看到文件 typedoc.json 已被删除。但是为什么这个--tsconfig?有一个 tsconfig.json 文件,但我看不到 rimraf 正在做任何事情

"scripts": {
    "build": "tsdx build --transpileOnly --entry ./src/index.js",
    "prebuild": "npm run docs",
    "prepublishOnly": "npm run build",
    "docs": "rimraf typedoc.json && typedoc --tsconfig",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},

这段代码的来源是notistackpackage.json

【问题讨论】:

    标签: node.js scripting package.json npm-scripts


    【解决方案1】:

    首先,rimraf 不会对tsconfig.json 文件做任何事情。重要的是要了解package.json文件中的docs脚本,即这部分;

    "docs": "rimraf typedoc.json && typedoc --tsconfig",
    

    由两个单独的命令组成,它们一起被称为“复合命令”。

    typedoc --tsconfig 部分是第二个命令,它不是 rimraf 命令的一部分,因为它位于 && 运算符的右侧。 --tsconfig 部分实际上是typedoc 命令的参数(...不是rimraf 命令的参数)。

    本质上,typedoc 命令及其关联的--tsconfig 参数位于&& 运算符的右侧,只有在其左侧的命令(即第一条命令rimraf typedoc.json),成功完成,退出代码为零。

    typedoc 命令用于为 TypeScript 项目生成文档。

    typedoc 命令的--tsconfig 参数在documentation 中描述如下

    --tsconfig <path/to/tsconfig.json>

    指定应该加载的打字稿配置文件。如果未指定,TypeDoc 将在当前目录中查找“tsconfig.json”。

    注意:在您使用--tsconfig 参数时,它没有指定tsconfig.json 文件的自定义文件路径,因此它使用当前目录中的路径。

    【讨论】:

    • 谢谢,如何 "prebuild": "npm run docs",`` 运行 doc 而不是运行一些 doc.script 文件
    • 这是因为prebuild 脚本以npm-run-script 命令开头。请参阅我的回答 here,它描述了如何在 package.json 中从另一个命令调用一个命令 - 它应该可以帮助您更好地理解。
    猜你喜欢
    • 2013-11-23
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 1970-01-01
    • 2019-10-22
    相关资源
    最近更新 更多