为什么TypeScript编译器会忽略tsconfig.json?

时间:2021-02-17 23:37:34

I have this file, pasted from a tutorial (and let's face it, the disparity between docs, tuts, and examples is astounding):

我有这个文件,从教程中粘贴(让我们面对它,文档,tuts和示例之间的差异令人震惊):

/scripts/tsconfig.json:

/scripts/tsconfig.json:

{
    "compilerOptions": {
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "module": "commonjs",
        "noEmitOnError": true,
        "noImplicitAny": false,
        "outDir": "../wwwroot/appScripts/",
        "removeComments": false,
        "sourceMap": true,
        "target": "es5",
        "moduleResolution": "node"
    },
    "exclude": [
        "node_modules",
        "typings/index",
        "typings/index.d.ts"
    ]
}

Options are set to compile on save, but whenever I save a TypeScript file, the JavaScript output ends up 'under', or 'attached to', the source file:

选项设置为在保存时编译,但每当我保存一个TypeScript文件时,JavaScript输出最终在源文件的“下”或“附加到”:

TypeScript
|
--test.ts 
    |
    --test.js

, and that is physically in the same directory as the source, /TypeScript. If tsconfig.json is missing, the compiler complains, but when it's present, and it definitely is, the compiler ignores the "outDir": "../wwwroot/appScripts/" setting.

,它与源/ TypeScript在同一目录中。如果缺少tsconfig.json,编译器会抱怨,但是当它出现时,肯定是,编译器会忽略“outDir”:“../wwwroot/appScripts/”设置。

I am really to new to Gulp, but the Gulp task looks OK to me:

我真的是Gulp的新手,但Gulp的任务看起来对我很好:

var tsProject = ts.createProject('scripts/tsconfig.json');
gulp.task('ts', function (done) {
    //var tsResult = tsProject.src()
    var tsResult = gulp.src([
            "scripts/*.ts"
    ])
        .pipe(ts(tsProject), undefined, ts.reporter.fullReporter());
    return tsResult.js.pipe(gulp.dest('./wwwroot/appScripts'));
});

1 个解决方案

#1


4  

Options are set to compile on save

选项设置为在保存时编译

When you save a file it is automatically compiling that single file and files imported on that file. Turn off auto compile option from your IDE, so compiler will consider tsconfig.json file.

保存文件时,它会自动编译该文件中导入的单个文件和文件。从IDE关闭自动编译选项,因此编译器将考虑tsconfig.json文件。

When input files are specified on the command line, tsconfig.json files are ignored.

在命令行中指定输入文件时,将忽略tsconfig.json文件。

The presence of a tsconfig.json file in a directory indicates that the directory is the root of a TypeScript project. The tsconfig.json file specifies the root files and the compiler options required to compile the project. A project is compiled in one of the following ways:

目录中存在tsconfig.json文件表示该目录是TypeScript项目的根目录。 tsconfig.json文件指定编译项目所需的根文件和编译器选项。项目以下列方式之一编译:

Using tsconfig.json

使用tsconfig.json

  1. By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain.

    通过在没有输入文件的情况下调用tsc,在这种情况下,编译器将从当前目录开始搜索tsconfig.json文件并继续执行父目录链。

  2. By invoking tsc with no input files and a --project (or just -p) command line option that specifies the path of a directory containing a tsconfig.json file.

    通过调用没有输入文件的tsc和--project(或只是-p)命令行选项来指定包含tsconfig.json文件的目录的路径。

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

#1


4  

Options are set to compile on save

选项设置为在保存时编译

When you save a file it is automatically compiling that single file and files imported on that file. Turn off auto compile option from your IDE, so compiler will consider tsconfig.json file.

保存文件时,它会自动编译该文件中导入的单个文件和文件。从IDE关闭自动编译选项,因此编译器将考虑tsconfig.json文件。

When input files are specified on the command line, tsconfig.json files are ignored.

在命令行中指定输入文件时,将忽略tsconfig.json文件。

The presence of a tsconfig.json file in a directory indicates that the directory is the root of a TypeScript project. The tsconfig.json file specifies the root files and the compiler options required to compile the project. A project is compiled in one of the following ways:

目录中存在tsconfig.json文件表示该目录是TypeScript项目的根目录。 tsconfig.json文件指定编译项目所需的根文件和编译器选项。项目以下列方式之一编译:

Using tsconfig.json

使用tsconfig.json

  1. By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain.

    通过在没有输入文件的情况下调用tsc,在这种情况下,编译器将从当前目录开始搜索tsconfig.json文件并继续执行父目录链。

  2. By invoking tsc with no input files and a --project (or just -p) command line option that specifies the path of a directory containing a tsconfig.json file.

    通过调用没有输入文件的tsc和--project(或只是-p)命令行选项来指定包含tsconfig.json文件的目录的路径。

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html