我挣扎了很长时间。我的解决方案是删除你所有的
///
形成您的文件(这样项目中的所有打字稿文件都可以互相看到)。
然后启用选项以分别编译每个打字稿。
接下来使用 grunt-concat(不幸的是,您必须提供文件夹的顺序才能使其工作)并将模块文件中的每个 js 文件合并为一个。
如果文件更改,您可以使用 grunt watch 连接每个模块,这样您就不必再编译所有项目了:)
Visual Studio Typescript Tools 也将直接在 Visual Studio 错误列表中显示任何错误。
我的示例 grunt 配置:
module.exports = function (grunt) {
grunt.initConfig({
concat: {
options: {
separator: '\n',
},
app: {
src: [
'Src/Application/Modules/**/*.js',
'Src/Application/Config/*.js',
'Src/Application/*.js'
],
dest: 'Scripts/App/App.js'
},
ui: {
src: ['Src/UI/**/*.js'],
dest: 'Scripts/App/UI.js'
}
},
watch: {
app: {
files: ['Src/Application/**/*.js'],
tasks: ['concat:app'],
options: {
nospawn: true
}
},
ui: {
files: ['Src/UI/**/*.js'],
tasks: ['concat:ui'],
options: {
nospawn: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
};
关于 basarat 的回复我想指出,如果您使用 grunt-ts,您必须在文件中提供引用,并且引用将自动解析。这意味着如果您的模块 A 引用了模块 B 中的文件,则该文件将包含在您的输出文件 A.js 中