Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Compile on Save for Typescript in Visual Studio with Gulp
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"module": "amd",
"inlineSources": true,
"outFile": "../wwwroot/js/ts/scripts.js"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
/// <binding AfterBuild='min' Clean='clean' ProjectOpened='watch' />
"use strict";
var gulp = require("gulp"),
rimraf = require("rimraf"),
concat = require("gulp-concat"),
cssmin = require("gulp-cssmin"),
uglify = require("gulp-uglify"),
tsc = require('gulp-typescript'),
sourcemaps = require('gulp-sourcemaps'),
tsProject = tsc.createProject('./Scripts/_tsconfig.json'),
fs = require("fs");
var paths = {
webroot: "./wwwroot/"
};
paths.ts = "./Scripts/**/*.ts";
paths.js = paths.webroot + "js/**/*.js";
paths.minJs = paths.webroot + "js/**/*.min.js";
paths.css = paths.webroot + "css/**/*.css";
paths.minCss = paths.webroot + "css/**/*.min.css";
paths.concatJsDest = paths.webroot + "js/site.min.js";
paths.concatCssDest = paths.webroot + "css/site.min.css";
gulp.task("clean:js", function (cb) {
rimraf(paths.concatJsDest, cb);
});
gulp.task("clean:css", function (cb) {
rimraf(paths.concatCssDest, cb);
});
gulp.task("clean", ["clean:js", "clean:css"]);
gulp.task("min:js", function () {
return gulp.src([paths.js, "!" + paths.minJs], { base: "." })
.pipe(concat(paths.concatJsDest))
.pipe(uglify())
.pipe(gulp.dest("."));
});
gulp.task("min:css", function () {
return gulp.src([paths.css, "!" + paths.minCss])
.pipe(concat(paths.concatCssDest))
.pipe(cssmin())
.pipe(gulp.dest("."));
});
gulp.task("min", ["min:js", "min:css"]);
gulp.task('compile-ts', function () {
var tsResult = gulp.src(paths.ts)
.pipe(sourcemaps.init())
.pipe(tsc(tsProject));
tsResult.dts.pipe(gulp.dest(paths.webroot));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.webroot));
});
gulp.task('watch', function () {
gulp.watch([paths.ts], ['compile-ts']);
});
{
"name": "ASP.NET",
"version": "0.0.0",
"devDependencies": {
"gulp": "3.8.11",
"gulp-concat": "2.5.2",
"gulp-cssmin": "0.1.7",
"gulp-uglify": "1.2.0",
"rimraf": "2.2.8",
"gulp-sourcemaps": "1.6.0",
"gulp-typescript": "2.10.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment