文件更改时 grunt-ts 手表不工作

grunt-ts watch not working when file changed

我正在使用 grunt:

  "dev-build": {
                src: ["src/**/*.ts", "typings/vendors.d.ts","typings/tsd.d.ts", "!libs/**/*.ts"],
                    outDir: "artifacts/dev",
                    watch: "src/**/*",
                    options: {
                        // comments: true,
                  //      baseDir: 'src/',
                        module: "amd",
                        target: "es5",
                        sourceMap: true,
                        declaration: true, //inlineSourceMap :true,
                        //emitDecoratorMetadata:true,
                        //experimentalDecorators:true,

                    }               

            }

一切编译正常:

"TypeScript compilation complete: 8.97s for 256 TypeScript files."

但是在不更改代码的情况下更改文件(添加换行符)后,编译会随着手表中断:

### changed  >>src/FxsPortal/FxsBaseItemViewModel.ts
Compiling...
### Fast Compile >>src/FxsPortal/FxsBaseItemViewModel.ts
Using tsc v1.6.2
C:/dev/AscendXYZ Portal/src/FxsPortal/FxsBaseItemViewModel.ts(2,21): error TS2307: Cannot find module 'knockout'.

我知道没有错误,因为我可以手动编译它。我似乎不明白为什么它在 ts-grunt 的 watch 触发时不起作用。

I dont seem to understand why it do not work when the watch of ts-grunt triggers.

可以安全地忽略这些错误。它们出现的原因是因为 grunt 只是从命令行驱动 tsc 并且只向它传递单个文件。

更多

如果您真的很关心,您可以使用reference标签引入全局.d.ts文件(不通过[=13引入的文件) =]).但我强烈建议不要这样做。你应该有一个 IDE 打开,它会给你 真正的 错误(...cough atom-ts ...

作为参考,我只是想分享一下我是如何使用外部手表解决这个问题的。

 watch: {
            devBuildWatch: {
                files: ['src/**/*'],
                tasks: ['ts:devBuild'],
                options: {
                    spawn: false,
                },
            }
        },

和一个 onchange 动作

 var changedFiles = {};

    var onChange = grunt.util._.debounce(function () {
        grunt.config('ts.devBuild.src', Object.keys(changedFiles).concat([ "typings/vendors.d.ts","typings/tsd.d.ts", "!libs/**/*.ts"]));
        changedFiles = Object.create(null);
    }, 50);

    grunt.event.on('watch', function (action, filepath) {
        changedFiles[filepath] = action;
        onChange();
    });