我正在尝试将一个打字机应用程序从ASP.NET MVC环境中导入一个单独的应用程序,以分离前端和后端需求。
打字稿保持不变,我尝试用gulp
编译打字稿,但代码似乎没有编译。我关注了Dan Wahlin撰写的this博文。但打字稿似乎没有编译。我在安装了Visual Studio 2015 Premium的Windows 8.1笔记本电脑上。
我项目的目录结构如下:
/
-- App/
---- Controllers/
------ xxController.ts
-- Scripts/
---- typings/
------ xxlibrary/
-------- library.d.ts
---- tsd.d.ts
我拥有的文件如下:
Gulpfile.config.js:
'use strict';
var GulpConfig = (function () {
function gulpConfig() {
this.source = '/App';
this.tsOutputPath = '/Scripts';
this.allJavaScript = ['/Scripts/**/*.js'];
this.allTypeScript = this.source + '/**/*.ts';
this.typings = '/Scripts/typings';
this.libraryTypeScriptDefinitions = this.typings + '/**/*.ts';
}
return gulpConfig;
})();
module.exports = GulpConfig;
请注意,当我使用“./”符号时,如Dan Wahlin所示,配置gulp给了我一个例外:
[11:08:11] Using gulpfile D:\Files\Work\Source\ImageManagement\Imagemanagement.App\Gulpfile.js
[11:08:11] Starting 'ts-lint'...
[11:08:11] Starting 'compile-ts'...
stream.js:94
throw er; // Unhandled stream error in pipe.
^
SyntaxError: Unexpected token
gulpfile.js:
'use strict';
var gulp = require('gulp'),
debug = require('gulp-debug'),
inject = require('gulp-inject'),
tsc = require('gulp-typescript'),
tslint = require('gulp-tslint'),
sourcemaps = require('gulp-sourcemaps'),
del = require('del'),
Config = require('./gulpfile.config'),
tsProject = tsc.createProject('tsconfig.json'),
browserSync = require('browser-sync'),
superstatic = require('superstatic');
var config = new Config();
/**
* Compile TypeScript and include references to library and app .d.ts files.
*/
gulp.task('compile-ts', function () {
var sourceTsFiles = [config.allTypeScript, //path to typescript files
config.libraryTypeScriptDefinitions]; //reference to library .d.ts files
var tsResult = gulp.src(sourceTsFiles)
.pipe(sourcemaps.init())
.pipe(tsc(tsProject));
tsResult.dts.pipe(gulp.dest(config.tsOutputPath));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.tsOutputPath));
});
当我运行这个gulpfile.js时,没有抛出任何错误,但Scripts
中没有输出正如我所期望的那样。
[11:15:08] Using gulpfile D:\Files\Work\Source\ImageManagement\Imagemanagement.App\Gulpfile.js
[11:15:08] Starting 'compile-ts'...
[11:15:08] Finished 'compile-ts' after 6.84 ms
Process terminated with code 0.
答案 0 :(得分:0)
好的,我发现了这个问题。 当我改变这个:
'use strict';
var GulpConfig = (function () {
function gulpConfig() {
[...]
this.allTypeScript = this.source + '/**/*.ts';
[...]
this.libraryTypeScriptDefinitions = this.typings + '/**/*.ts';
}
return gulpConfig;
})();
module.exports = GulpConfig;
要
'use strict';
var GulpConfig = (function () {
function gulpConfig() {
[...]
this.allTypeScript = './App/**/*.ts';
[...]
this.libraryTypeScriptDefinitions = './Scripts/typings/**/*.ts';
}
return gulpConfig;
})();
module.exports = GulpConfig;
它运作得很好。不知道为什么会这样。