From dd6da7e650fd360d4807bdd726344841ea691c2e Mon Sep 17 00:00:00 2001 From: "tony.deng" Date: Wed, 28 Feb 2018 11:48:37 +0800 Subject: [PATCH] Upgrade code --- gulpfile.js | 9 -- package.json | 13 +-- src/style/common/pc/_common.styl | 1 - src/style/lib/phone/animate.styl | 1 - task.js | 137 ++++++++++++++++++------------- 5 files changed, 89 insertions(+), 72 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 7459ba3..5d9481e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -48,15 +48,6 @@ let colorLog = function (text, color) { let userInput = 1; //输入值 -gulp.task('server', function() { - - -}); - -gulp.task('build', function (cb) { - -}); - //复制模板 gulp.task('copy-pc', function () { return gulp.src(config.base + '/template/tpl-pc/**/*.*') diff --git a/package.json b/package.json index 15035db..e258819 100644 --- a/package.json +++ b/package.json @@ -9,18 +9,21 @@ "author": "dengtongyu", "license": "ISC", "devDependencies": { - "art-template": "^4.12.1", - "browser-sync": "^2.18.11", + "art-template": "^4.12.2", + "babel-core": "^6.26.0", + "babel-preset-env": "^1.6.1", + "browser-sync": "^2.23.6", "gulp": "^3.9.1", + "gulp-babel": "^7.0.1", "gulp-htmlmin": "^3.0.0", "gulp-notify": "^3.2.0", "gulp-plumber": "^1.2.0", - "gulp-stylus": "^2.6.0", + "gulp-stylus": "^2.7.0", "gulp-swig": "^0.8.0", "gulp-tmod": "^2.0.3", - "gulp-uglify": "^2.1.2", + "gulp-uglify": "^3.0.0", "gulp-webpack": "^1.5.0", "http-proxy-middleware": "^0.17.4", - "run-sequence": "^1.2.2" + "run-sequence": "^2.2.1" } } diff --git a/src/style/common/pc/_common.styl b/src/style/common/pc/_common.styl index f6a7f35..1e7a0b9 100644 --- a/src/style/common/pc/_common.styl +++ b/src/style/common/pc/_common.styl @@ -1,4 +1,3 @@ -@charset "UTF-8"; /** * * @authors Tony.Deng (dengtongyu123@163.com) diff --git a/src/style/lib/phone/animate.styl b/src/style/lib/phone/animate.styl index b7d3755..3cd7c48 100644 --- a/src/style/lib/phone/animate.styl +++ b/src/style/lib/phone/animate.styl @@ -1,4 +1,3 @@ -@charset "UTF-8"; /*! * animate.css -https://daneden.me/animate diff --git a/task.js b/task.js index c81d09f..1180822 100644 --- a/task.js +++ b/task.js @@ -19,6 +19,8 @@ const lodash = require('lodash'); const path = require('path'); const plumber = require('gulp-plumber'); const notify = require('gulp-notify'); +const babel = require('gulp-babel'); +const runSequence = require('run-sequence'); let swigOpts = { defaults: { @@ -37,21 +39,6 @@ function onErrorHandler(err) { this.emit('end'); } -//代理配置 -let proxy = proxyMiddleware( - ['/node_modules','/res/images/userimage'], - { - //target:'http://172.26.68.35:8085'// - target: 'http://node.dengtongyu.com' - //target:'http://47.94.23.46:80' - } -); -let proxy2 = proxyMiddleware( - ['/data/getPictureList'], - { - target: 'http://localhost:8080' - } -); function pathType(filePath) { let type = path.parse(filePath).ext; @@ -85,18 +72,69 @@ module.exports = function (pathConfig,config) { function watcherListFun(watchList) { for (var i = 0; i < watchList.length; i++) { + if(watchList[i].taskName[0] == 'uglify_build' || watchList[i].taskName[0] == 'htmlmin_build') continue; + gulp.watch(watchList[i].watchPath,watchList[i].taskName).on('change', function (event) { - let fileType = pathType(event.path); + let fileType = pathType(event.path); pathConfig[watchList[fileType].taskPath] = path.relative(__dirname,event.path); //added为新增,deleted为删除,changed为改变 //变化类型 和 变化的文件的路径 - console.log(event.type + ' : ' + pathConfig[watchList[fileType].taskPath]); + console.log(event.type + ' : ' + pathConfig[watchList[fileType].taskPath]); + }); } } + let watchList = [{ + watchPath:pathConfig.styleBuildPath, + taskName:['stylus_build'], + taskPath:'styleChangePath' + }, + { + watchPath:pathConfig.htmlBuildPath, + taskName:['html_build'], + taskPath:'swigChangePath' + }, + { + watchPath:pathConfig.htmlminBuildPath, + taskName:['htmlmin_build'], + taskPath:'htmlminChangePath' + }, + { + watchPath:pathConfig.scriptBuildPath, + taskName:['js_build'], + taskPath:'scriptChangePath' + }, + { + watchPath:pathConfig.uglifyBuildPath, + taskName:['uglify_build'], + taskPath:'uglifyChangePath' + }, + { + watchPath:pathConfig.tmodBuildPath, + taskName:['tmodjs_build'], + taskPath:'tmodChangePath' + }]; + //server任务 gulp.task('server', function () { + + //代理配置 + let proxy = proxyMiddleware( + ['/node_modules','/res/images/userimage'], + { + //target:'http://172.26.68.35:8085'// + target: 'http://node.dengtongyu.com' + //target:'http://47.94.23.46:80' + } + ); + let proxy2 = proxyMiddleware( + ['/data/getPictureList'], + { + target: 'http://localhost:8080' + } + ); + browserSync({ host: 'localhost', open: 'external', @@ -107,42 +145,10 @@ module.exports = function (pathConfig,config) { baseDir: 'build', middleware: [proxy,proxy2] } - }); - - let watchList = [ - { - watchPath:pathConfig.styleBuildPath, - taskName:['stylus_build'], - taskPath:'styleChangePath' - }, - { - watchPath:pathConfig.htmlBuildPath, - taskName:['swig_build'], - taskPath:'swigChangePath' - }, - { - watchPath:pathConfig.htmlminBuildPath, - taskName:['htmlmin_build'], - taskPath:'htmlminChangePath' - }, - { - watchPath:pathConfig.scriptBuildPath, - taskName:['webpack_build'], - taskPath:'scriptChangePath' - }, - { - watchPath:pathConfig.uglifyBuildPath, - taskName:['uglify_build'], - taskPath:'uglifyChangePath' - }, - { - watchPath:pathConfig.tmodBuildPath, - taskName:['tmod_build'], - taskPath:'tmodChangePath' - } - ] - - watcherListFun(watchList); + }); + + watcherListFun(watchList); + }); //stylus任务 @@ -178,9 +184,12 @@ module.exports = function (pathConfig,config) { gulp.task('webpack_build', function () { return gulp.src(pathConfig.scriptBuildPath) .pipe(plumber({errorHandler: onErrorHandler})) - .pipe(webpack( webPackConfig )) + .pipe(webpack( webPackConfig )) + .pipe(babel({ + presets: ['env'] + })) .pipe(gulp.dest(pathConfig.webpackOutPath)) - .on("end", reload); + .on("end", reload); }); //uglify任务 @@ -194,7 +203,7 @@ module.exports = function (pathConfig,config) { //tmod任务 gulp.task('tmod_build', function () { - console.log(pathConfig.tmodBuildPath); + //console.log(pathConfig.tmodBuildPath); return gulp.src(pathConfig.tmodBuildPath) .pipe(plumber({errorHandler: onErrorHandler})) .pipe(tmodjs({ @@ -205,4 +214,20 @@ module.exports = function (pathConfig,config) { })) .on("end", reload); }); + + //watch html任务 + gulp.task('html_build', function () { + runSequence('swig_build','htmlmin_build'); + }); + + //watch js任务 + gulp.task('js_build', function () { + //console.log('执行了js_build') + runSequence('webpack_build', 'uglify_build'); + }); + + //watch tmodjs任务 + gulp.task('tmodjs_build', function () { + runSequence('tmod_build', 'webpack_build', 'uglify_build'); + }); } \ No newline at end of file