警告:错误 TS18002:配置文件中的“文件”列表为空

问题描述 投票:0回答:2

我正在使用 TypeScript 2.1.5.0。我已经配置了

grunt-typescript-using-tsconfig
插件,如下所示,但是当我执行任务时,我在主题行中收到错误。

问题在于

tsconfig.json
属性
"files":[]
。我在使用
gulp-typescript
时没有遇到这个错误。您建议我进行不同的配置吗?我对这个插件的
gruntfile.js
还是
tsconfig.json
?或者您可以推荐一个不同的 grunt 插件,它可以成功挂接到
tsconfig.json
并按预期处理打字稿任务吗?

typescriptUsingTsConfig: {
    basic: {
        options: {
            rootDir: "./tsScripts" 
        }
    }
}
node.js typescript npm gruntjs
2个回答
0
投票

或者您可以推荐一个不同的 grunt 插件,它将成功挂接到 tsconfig.json 并按预期处理打字稿任务吗?

gulp typescript 支持 tsconfig :https://github.com/ivogabe/gulp-typescript/#using-tsconfigjson

var tsProject = ts.createProject('tsconfig.json');
gulp.task('scripts', function() {
    var tsResult = gulp.src(tsProject.src())
        .pipe(tsProject());

    return tsResult.js.pipe(gulp.dest('release'));
});

0
投票

尝试设置您的

Gruntfile.js
配置,如以下要点所示:

Gruntfile.js

module.exports = function(grunt) {

    grunt.initConfig({

        typescriptUsingTsConfig: {
            basic: {
                options: {
                    rootDir: './'
                }
            }
        }

    });

    grunt.loadNpmTasks('grunt-typescript-using-tsconfig');

    grunt.registerTask('default', [
        'typescriptUsingTsConfig'
    ]);

};

注意

rootDir
的值设置为
./
(即与
Gruntfile.js
相同的文件夹)。


tsconfig.json

然后确保您的

tsconfig.json
配置为包含要编译为
.ts
的所有
.js
文件的列表。例如:

{
  "compilerOptions": {
    "outDir": "./dist"
  },
  "files": [
    "./tsScripts/a.ts",
    "./tsScripts/b.ts",
    "./tsScripts/c.ts"
  ]
}

当然您还可以在 tsconfig.json

中设置其他编译器选项

目录结构

上面的配置假设目录结构如下,但是您可以根据需要调整代码示例:

foo
├── Gruntfile.js
├── tsconfig.json
├── tsScripts
│   ├── a.ts
│   ├── b.ts
│   └── c.ts
└── node_modules
    └── ...

奔跑的咕噜声

cd
到项目文件夹,(在这些示例中名为
foo
,然后运行:

$ grunt


输出

运行 grunt 将创建一个名为 dist 的文件夹,并将所有

.js
文件输出到其中。例如:

foo
├── dist
│   ├── a.js
│   ├── b.js
│   └── c.js
└── ...

如果您希望将生成的

.js
文件输出到与源
.ts
文件相同的文件夹,(即不输出到“dist”文件夹),只需从
"outDir": "./dist"
中排除
ts.config.json
部分.

© www.soinside.com 2019 - 2024. All rights reserved.