tsc --build与tsc --project的区别

22

我有一个monorepo,我正在将一个子项目转换为TypeScript。 在我的npm脚本中,我有:

"build-proj1":"tsc --build ./proj1/tsconfig.json"

它可以工作,但是我注意到它特别慢。

当我改为:

"build-proj1":"tsc --project ./proj1/tsconfig.json"

它执行速度更快,产生相同的结果...

我的tsconfig.json供参考:

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "module": "CommonJS",
        "target": "es2018",
        "lib": ["es2019"],
        "noImplicitAny": false,
        "declaration": false,
        "allowJs": true,
        "preserveConstEnums": true,
        "outDir": "./dist",
        "sourceMap": true,
        "skipLibCheck": true,
        "baseUrl": "./",
        "types": ["node"],
        "typeRoots": ["../node_modules/@types"],
        "strict": true,
        "esModuleInterop": true,
        "disableReferencedProjectLoad": true,
        "paths": {
            "root-common/*": ["../common/*"],
            "root-config/*": ["../config/*"],
            "root/*": ["../*"]
        }
    },
    "include": ["./**/*"],
    "exclude": ["node_modules", "**/*.spec.ts", "**/*.test.*", "./dist/**/*", "../common/**/*test.*"]
}

我的问题是--build--project之间有什么区别,为什么--build--project慢得多?


1
--build 对我来说运行更快。在此处阅读更多信息:https://www.typescriptlang.org/docs/handbook/project-references.html - Yukulélé
1个回答

11

根据tsc --help

  --project, -p  Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.

  --build, -b  Build one or more projects and their dependencies, if out of date

--project 选项编译单个项目。

--build 选项可以被看作是一个构建协调器,它查找引用的项目,检查它们是否是最新的,并按正确的顺序构建过时的项目。有关详细信息,请参见文档

回答您的第二个问题,--build 选项更慢,因为它还编译依赖项,但在第二次运行时应更快,因为它只编译过时的项目。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接