From 4a6bbe93b225f7cc978ca042862185485ec91823 Mon Sep 17 00:00:00 2001 From: "tony.deng" Date: Mon, 19 Feb 2018 21:33:51 +0800 Subject: [PATCH] update code --- gulpfile.js | 2 +- package.json | 2 ++ task.js | 32 +++++++++++++++++++++++++------- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 75d074e..7459ba3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -74,7 +74,7 @@ function setPath(pathName) { pathConfig.currPath = pathName; //stylus build目录 - pathConfig.styleBuildPath = config.base + '/pages/' + pathName + '/**/*.styl'; + pathConfig.styleBuildPath = config.base + '/pages/' + pathName + '/**/!(_)*.styl'; //swig build目录 pathConfig.htmlBuildPath = config.base + '/pages/' + pathName + '/**/*.htm'; diff --git a/package.json b/package.json index 4623353..15035db 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "browser-sync": "^2.18.11", "gulp": "^3.9.1", "gulp-htmlmin": "^3.0.0", + "gulp-notify": "^3.2.0", + "gulp-plumber": "^1.2.0", "gulp-stylus": "^2.6.0", "gulp-swig": "^0.8.0", "gulp-tmod": "^2.0.3", diff --git a/task.js b/task.js index 6b716ff..c81d09f 100644 --- a/task.js +++ b/task.js @@ -17,6 +17,8 @@ const reload = browserSync.reload; const proxyMiddleware = require('http-proxy-middleware'); const lodash = require('lodash'); const path = require('path'); +const plumber = require('gulp-plumber'); +const notify = require('gulp-notify'); let swigOpts = { defaults: { @@ -25,6 +27,16 @@ let swigOpts = { } }; +function onErrorHandler(err) { + notify.onError({ + title: "Webpage", + subtitle: err.plugin + " error!", + message: "Error: <%= error.message %>", + sound: "Beep" + })(err); + this.emit('end'); +} + //代理配置 let proxy = proxyMiddleware( ['/node_modules','/res/images/userimage'], @@ -136,16 +148,18 @@ module.exports = function (pathConfig,config) { //stylus任务 gulp.task('stylus_build', function () { return gulp.src(pathConfig.styleBuildPath, config) + .pipe(plumber({errorHandler: onErrorHandler})) .pipe(stylus({ compress: true })) - .pipe(gulp.dest(config.build)) + .pipe(gulp.dest(config.build)) .on("end", reload); }); //swig任务 gulp.task('swig_build', function () { - return gulp.src(pathConfig.htmlBuildPath, config) + return gulp.src(pathConfig.htmlBuildPath, config) + .pipe(plumber({errorHandler: onErrorHandler})) .pipe(swig(swigOpts)) .pipe(gulp.dest(config.build)) .on("end", reload); @@ -153,15 +167,17 @@ module.exports = function (pathConfig,config) { //htmlmin任务 gulp.task('htmlmin_build', function () { - return gulp.src(pathConfig.htmlminBuildPath, config) + return gulp.src(pathConfig.htmlminBuildPath, config) + .pipe(plumber({errorHandler: onErrorHandler})) .pipe(htmlmin({collapseWhitespace: true})) - .pipe(gulp.dest(config.build)) + .pipe(gulp.dest(config.build)) .on("end", reload); }); //webpack任务 gulp.task('webpack_build', function () { - return gulp.src(pathConfig.scriptBuildPath) + return gulp.src(pathConfig.scriptBuildPath) + .pipe(plumber({errorHandler: onErrorHandler})) .pipe(webpack( webPackConfig )) .pipe(gulp.dest(pathConfig.webpackOutPath)) .on("end", reload); @@ -169,7 +185,8 @@ module.exports = function (pathConfig,config) { //uglify任务 gulp.task('uglify_build', function () { - return gulp.src(pathConfig.uglifyBuildPath, {base: config.build}) + return gulp.src(pathConfig.uglifyBuildPath, {base: config.build}) + .pipe(plumber({errorHandler: onErrorHandler})) .pipe(uglify()) .pipe(gulp.dest(config.build)) .on("end", reload); @@ -178,7 +195,8 @@ module.exports = function (pathConfig,config) { //tmod任务 gulp.task('tmod_build', function () { console.log(pathConfig.tmodBuildPath); - return gulp.src(pathConfig.tmodBuildPath) + return gulp.src(pathConfig.tmodBuildPath) + .pipe(plumber({errorHandler: onErrorHandler})) .pipe(tmodjs({ templateBase: pathConfig.tmodBasePath, output: pathConfig.tmodOutPath,