[TypeScript] Using Gulp with TypeScript

Package.json:

复制代码
{
  "name": "typescript",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "gulp": "^3.9.0",
    "gulp-typescript": "^2.8.0"
  },
  "devDependencies": {
    "del": "^1.2.1",
    "gulp-concat": "^2.6.0",
    "gulp-plumber": "^1.0.1",
    "gulp-uglify": "^1.2.0",
    "run-sequence": "^1.1.2"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}
复制代码

 

Use:

gulpfile.js

复制代码
/**
 * Created by Answer1215 on 8/17/2015.
 */
var gulp = require('gulp'),
    plumber = require('gulp-plumber'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    ts = require('gulp-typescript'),
    runSequence = require('run-sequence'),
    del = require('del'),
    tsPath = 'typescript/*.ts',
    jsPath = './js',
    compilePath = 'js/compiled',
    dist = 'js/dist';

gulp.task('build', function(callback) {
    runSequence('clean', ['typescript','compressScripts'], callback);
});

gulp.task('compressScripts', function() {
    gulp.src([
        compilePath + 'typescript/*.js'
    ])
        .pipe(plumber())
        .pipe(concat('bundle.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest(dist));
});

gulp.task('typescript', function() {
    var tsResult = gulp.src(tsPath)
        .pipe(ts({
            target: 'ES5',
            noExternalResolve: true,
            declarationFiles: false
        }));

    tsResult.dts.pipe(gulp.dest(compilePath + '/tsdefinitions'));
    return tsResult.js.pipe(gulp.dest(compilePath + '/typescript'))
});

gulp.task('clean', function(callback) {
    del([jsPath], {force: true}, callback);
});

gulp.task('watch', function() {
    gulp.watch([tsPath], ['typescript']);
});

gulp.task('default', function(callback) {
    runSequence('build', ['watch'], callback);
});
复制代码

 

posted @   Zhentiw  阅读(463)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示