简体   繁体   中英

Gulp and TS compilation

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?

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'));        
});    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM