Gulp and TS compilation

元气小坏坏 提交于 2019-12-20 06:39:05

问题


I have defined task in my gulp file:

gulp.task('dev:build:scripts', function () {
    var tsResult = tsProject.src()
        .pipe(sourcemaps.init())
        .pipe(ts(tsProject));
});

Which takes all of the scripts, and creates source maps to the static/dist. My tsProject:

var tsProject = ts.createProject('tsconfig.json', {
    outDir: paths.dist +'/app'
});

And my tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "outDir": "static/dist/app"
  },
  "exclude": [
    "node_modules"
  ]
}

However, after the gulp runs the project, it doesnt compile the JS and doesnt create sourcemaps - it only does so, when I make a change to any ts file. How can I fix this?


回答1:


I think you forgot to actually write your results. Try this one:

gulp.task('dev:build:scripts', () => 
{
    var tsProject = ts.createProject('tsconfig.json');

    var tsResult = tsProject.src()
        .pipe(sourcemaps.init())   
        .pipe(ts(tsProject));  

    return tsResult.js.pipe(sourcemaps.write()).pipe(gulp.dest(paths.dist +'/app'));        
});    


来源:https://stackoverflow.com/questions/35956888/gulp-and-ts-compilation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!