2017-03-27 43 views
1

我正在使用gulp预处理LESS文件,但希望在调试时对其进行更改,以便我可以即时看到它们。如何在调试时运行吞吐任务.net核心应用程序

我有以前的应用程序使用bundle config来做这件事,但想知道如何使用.net core使用gulp。

我目前有一个监视任务,用于在编辑代码时查找LESS文件的任何更改,但是这似乎只能在不调试站点的情况下启动我的进程任务。

感谢

回答

0

我Angular2和ASP.Net的核心工作,而只是this gulp file。如果你不需要它,你可以删除Angular2。

/* 
This file in the main entry point for defining Gulp tasks and using Gulp 
plugins. 
Click here to learn more. http://go.microsoft.com/fwlink/?LinkId=518007 
*/ 

var gulp = require('gulp'), 
    gp_clean = require('gulp-clean'), 
    gp_concat = require('gulp-concat'), 
    gp_less = require('gulp-less'), 
    gp_sourcemaps = require('gulp-sourcemaps'), 
    gp_typescript = require('gulp-typescript'), 
    gp_uglify = require('gulp-uglify'); 

/// Define paths 
var srcPaths = { 
    app: ['Scripts/app/main.ts', 'Scripts/app/**/*.ts'], 
    js: [ 
     'Scripts/js/**/*.js', 
     'node_modules/core-js/client/shim.min.js', 
     'node_modules/zone.js/dist/zone.js', 
     'node_modules/reflect-metadata/Reflect.js', 
     'node_modules/systemjs/dist/system.src.js', 
     'node_modules/typescript/lib/typescript.js', 
     'node_modules/ng2-bootstrap/bundles/ng2-bootstrap.min.js', 
     'node_modules/moment/moment.js' 
    ], 
    js_angular: [ 
     'node_modules/@angular/**' 
    ], 
    js_rxjs: [ 
     'node_modules/rxjs/**' 
    ], 
    less: [ 
     'Scripts/less/**/*.less' 
    ] 
}; 

var destPaths = { 
    app: 'wwwroot/app/', 
    css: 'wwwroot/css/', 
    js: 'wwwroot/js/', 
    js_angular: 'wwwroot/js/@angular/', 
    js_rxjs: 'wwwroot/js/rxjs/' 
}; 

// Compile, minify and create sourcemaps all TypeScript files and place them to wwwroot/app, together with their js.map files. 
gulp.task('app', ['app_clean'], function() { 
    return gulp.src(srcPaths.app) 
    .pipe(gp_sourcemaps.init()) 
    .pipe(gp_typescript(require('./tsconfig.json').compilerOptions)) 
    .pipe(gp_uglify({ mangle: false })) 
    .pipe(gp_sourcemaps.write('/')) 
    .pipe(gulp.dest(destPaths.app)); 
}); 

// Delete wwwroot/app contents 
gulp.task('app_clean', function() { 
    return gulp.src(destPaths.app + "*", { read: false }) 
    .pipe(gp_clean({ force: true })); 
}); 

// Copy all JS files from external libraries to wwwroot/js 
gulp.task('js', function() { 
    gulp.src(srcPaths.js_angular) 
    .pipe(gulp.dest(destPaths.js_angular)); 
    gulp.src(srcPaths.js_rxjs) 
    .pipe(gulp.dest(destPaths.js_rxjs)); 
    return gulp.src(srcPaths.js) 
    // .pipe(gp_uglify({ mangle: false })) // disable uglify 
    // .pipe(gp_concat('all-js.min.js')) // disable concat 
    .pipe(gulp.dest(destPaths.js)); 
}); 

// Delete wwwroot/js contents 
gulp.task('js_clean', function() { 
    return gulp.src(destPaths.js + "*", { read: false }) 
    .pipe(gp_clean({ force: true })); 
}); 

// Process all LESS files and output the resulting CSS in wwwroot/css 
gulp.task('less', ['less_clean'], function() { 
    return gulp.src(srcPaths.less) 
    .pipe(gp_less()) 
    .pipe(gulp.dest(destPaths.css)); 
}); 
// Delete wwwroot/css contents 
gulp.task('less_clean', function() { 
    return gulp.src(destPaths.css + "*.*", { read: false }) 
    .pipe(gp_clean({ force: true })); 
}); 

// Watch specified files and define what to do upon file changes 
gulp.task('watch', function() { 
    gulp.watch([srcPaths.app, srcPaths.js], ['app', 'js']); 
}); 

// Global cleanup task 
gulp.task('cleanup', ['app_clean', 'js_clean', 'less_clean']); 

// Define the default task so it will launch all other tasks 
gulp.task('default', ['app', 'js', 'less', 'watch']); 
+0

这基本上是我已经做了,但同时,该网站是在Visual Studio中被bebugged的gulp.watch不执行。所以这意味着如果我在调试站点时对LESS文件进行了更改,则手表不会触发再次处理文件的较少任务。 –

相关问题