我正在尝试使用gulp任务从JSON配置创建一个typescript类.
input
{
"ApiEndpoint": "http://localhost:5000/api"
}
Run Code Online (Sandbox Code Playgroud)
希望获得类似的输出
public static get ApiEndpoint(): string {
return "http://localhost:5000/api";
}
Run Code Online (Sandbox Code Playgroud)
尝试使用gulp-ts-config,但它在template.ts中抛出一个错误.不知何故,我无法使它在我的系统中工作.通过我们可以实现相同的其他gulp插件吗?
我的package.json
{
"devDependencies": {
"gulp": "3.9.1",
"gulp-ts-config": "1.0.15"
}
}
Run Code Online (Sandbox Code Playgroud)
我的 gulpfile.js
var gulp = require('gulp');
var gulpTsConfig = require('gulp-ts-config');
gulp.task('test', function () {
gulp.src('appsettings.json')
.pipe(gulpTsConfig('AppSettings'))
.pipe(gulp.dest('Scripts'))
});
Run Code Online (Sandbox Code Playgroud)
应用程序设置.json
{
"ApiEndpoint": "http://localhost:5000/api"
}
Run Code Online (Sandbox Code Playgroud)
运行任务后创建的打字稿
export class AppSettings {
public static get ApiEndpoint(): string {
return "http://localhost:5000/api";
}
}
Run Code Online (Sandbox Code Playgroud)
参考资料: https: //www.npmjs.com/package/gulp-ts-config
如果我更改 appSettings.json 以包含多个对象以转换为打字稿函数
{
"ApiEndpoint": "http://localhost:5000/api",
"HelloWorld": "HelloWorld"
}
Run Code Online (Sandbox Code Playgroud)
结果ts文件
export class AppSettings {
public static get ApiEndpoint(): string {
return "http://localhost:5000/api";
}
public static get HelloWorld(): string {
return "HelloWorld";
}
}
Run Code Online (Sandbox Code Playgroud)
从 gulp-ts-config 收到的具体错误是什么?我正在使用 Visual Studio 2017 和 npm 版本 5.5.1 和节点版本 v8.9.3
| 归档时间: |
|
| 查看次数: |
169 次 |
| 最近记录: |