首页 > 代码库 > 与你相遇好幸运,使用gulp流程化Typescript后端开发

与你相遇好幸运,使用gulp流程化Typescript后端开发

tsc --init

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": false,
        "outDir": "./dist"
    },
    "include": [
        "src/**/*.ts"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

 

gulpfiles.js


var gulp = require("gulp");
var ts = require("gulp-typescript");
var nodemon = require(‘gulp-nodemon‘);
var tsProject = ts.createProject("tsconfig.json");


gulp.task("build", function () {
    return tsProject.src()
        .pipe(tsProject())
        .js.pipe(gulp.dest("dist"));
});


gulp.task(‘start‘, function () {
    nodemon({
        script: ‘./dist/app.js‘
    })
});

gulp.task(‘watch‘, [‘build‘], function() {
    gulp.watch(‘src/**/*.ts‘, [‘build‘]);
    gulp.watch(‘dist/**/*.js‘, [‘start‘]);
});

gulp.task(‘default‘, [‘build‘]);

与你相遇好幸运,使用gulp流程化Typescript后端开发