@@ -5,13 +5,16 @@ const ejs = require('gulp-ejs');
55const ejshelper = require ( 'tmt-ejs-helper' ) ;
66const async = require ( 'async' ) ;
77const gulp = require ( 'gulp' ) ;
8+ const gulpif = require ( 'gulp-if' ) ;
89const less = require ( 'gulp-less' ) ;
910const lazyImageCSS = require ( 'gulp-lazyimagecss' ) ; // 自动为图片样式添加 宽/高/background-size 属性
1011const postcss = require ( 'gulp-postcss' ) ; // CSS 预处理
1112const posthtml = require ( 'gulp-posthtml' ) ; // HTML 预处理
1213const sass = require ( 'gulp-sass' ) ;
14+ const babel = require ( 'gulp-babel' ) ;
1315const Common = require ( path . join ( __dirname , '../common.js' ) ) ;
1416
17+
1518function dev ( projectPath , log , callback ) {
1619
1720 const bs = require ( 'browser-sync' ) . create ( ) ; // 自动刷新浏览器
@@ -33,11 +36,10 @@ function dev(projectPath, log, callback) {
3336 }
3437 }
3538
36-
3739 let paths = {
3840 src : {
3941 dir : path . join ( projectPath , './src' ) ,
40- img : path . join ( projectPath , './src/img/**/*.{JPG,jpg,png,gif}' ) ,
42+ img : path . join ( projectPath , './src/img/**/*.{JPG,jpg,png,gif,svg }' ) ,
4143 slice : path . join ( projectPath , './src/slice/**/*.png' ) ,
4244 js : path . join ( projectPath , './src/js/**/*.js' ) ,
4345 media : path . join ( projectPath , './src/media/**/*' ) ,
@@ -51,7 +53,8 @@ function dev(projectPath, log, callback) {
5153 dev : {
5254 dir : path . join ( projectPath , './dev' ) ,
5355 css : path . join ( projectPath , './dev/css' ) ,
54- html : path . join ( projectPath , './dev/html' )
56+ html : path . join ( projectPath , './dev/html' ) ,
57+ js : path . join ( projectPath , './dev/js' )
5558 }
5659 } ;
5760
@@ -101,7 +104,7 @@ function dev(projectPath, log, callback) {
101104 function compileSass ( cb ) {
102105 gulp . src ( paths . src . sass )
103106 . pipe ( sass ( ) )
104- . on ( 'error' , function ( error ) {
107+ . on ( 'error' , function ( error ) {
105108 console . log ( error . message ) ;
106109 log ( error . message ) ;
107110 } )
@@ -141,6 +144,24 @@ function dev(projectPath, log, callback) {
141144 } )
142145 }
143146
147+ //编译 JS
148+ function compileJs ( cb ) {
149+ gulp . src ( paths . src . js )
150+ . pipe ( babel ( {
151+ presets : [ 'es2015' , 'stage-2' ]
152+ } ) )
153+ . pipe ( gulp . dest ( paths . dev . js ) )
154+ . on ( 'end' , function ( ) {
155+ if ( cb ) {
156+ console . log ( 'compile JS success.' ) ;
157+ log ( 'compile JS success.' ) ;
158+ cb ( ) ;
159+ } else {
160+ reloadHandler ( ) ;
161+ }
162+ } )
163+ }
164+
144165//监听文件
145166 function watch ( cb ) {
146167 var watcher = gulp . watch ( [
@@ -314,7 +335,7 @@ function dev(projectPath, log, callback) {
314335 copyHandler ( 'slice' , cb ) ;
315336 } ,
316337 function ( cb ) {
317- copyHandler ( 'js' , cb ) ;
338+ compileJs ( cb ) ;
318339 } ,
319340 function ( cb ) {
320341 copyHandler ( 'media' , cb ) ;
0 commit comments