为什么TypeScript编译器忽略tsconfig.json? [英] Why is the TypeScript compiler ignoring tsconfig.json?

查看:463
本文介绍了为什么TypeScript编译器忽略tsconfig.json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,该文件是从教程中粘贴的(让我们面对现实,文档,tut和示例之间的差异令人震惊):

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

/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"
    ]
}

选项设置为在保存时进行编译,但是每当我保存TypeScript文件时,JavaScript输出最终都会在源文件的下"或附加到"上:

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
|
--test.ts 
    |
    --test.js

,并且实际上与源/TypeScript在同一目录中.如果缺少tsconfig.json,则编译器会抱怨,但是当它出现时(肯定是),编译器会忽略"outDir": "../wwwroot/appScripts/"设置.

, 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.

我真的是Gulp的新手,但是Gulp任务对我来说还可以:

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

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'));
});

推荐答案

选项设置为在保存时编译

Options are set to compile on save

保存文件时,它将自动编译该单个文件以及在该文件上导入的文件.在您的IDE中关闭自动编译选项,因此编译器将考虑tsconfig.json文件.

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.

在命令行上指定输入文件后, tsconfig.json文件将被忽略.

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

目录中存在tsconfig.json文件,表明该目录是TypeScript项目的根目录. 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

Using tsconfig.json

  1. 通过不带任何输入文件的tsc调用,在这种情况下,编译器会从当前目录开始并沿父目录链向上搜索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和一个--project(或仅-p)命令行选项来指定包含tsconfig.json文件的目录的路径.

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.

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

这篇关于为什么TypeScript编译器忽略tsconfig.json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆