1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | var gulp =require( 'gulp' ); var $ = require( 'gulp-load-plugins' )(); var open = require( 'open' ); var browserSync = require( 'browser-sync' ).create(); var reload = browserSync.reload; var app={ srcPath: 'src/' , devPath: 'build/' , prdPath: 'dist/' , } /*第3方依賴需拷貝複製於 src 和 dev 目錄下*/ gulp.task( 'lib' , function (){ gulp.src( 'bower_components/**/*.js' ) .pipe(gulp.dest(app.devPath + 'vender' )) .pipe(gulp.dest(app.prdPath + 'vender' )) .pipe(browserSync.stream()); }); gulp.task( 'html' , function (){ gulp.src(app.srcPath+ '**/*.html' ) .pipe(gulp.dest(app.devPath)) .pipe(gulp.dest(app.prdPath)) .pipe(browserSync.stream()); }); gulp.task( 'json' , function (){ gulp.src(app.srcPath+ 'data/**/*.json' ) .pipe(gulp.dest(app.devPath + 'data' )) .pipe(gulp.dest(app.prdPath + 'data' )) .pipe(browserSync.stream()); }); gulp.task( 'less' , function (){ gulp.src(app.srcPath+ 'style/index.less' ) .pipe($.less()) .pipe(gulp.dest(app.devPath + 'css' )) .pipe($.cssmin()) .pipe(gulp.dest(app.prdPath + 'css' )) .pipe(browserSync.stream()); }); gulp.task( 'js' , function (){ gulp.src(app.srcPath+ 'script/**/*.js' ) .pipe($.concat( 'index.js' )) .pipe(gulp.dest(app.devPath + 'js' )) .pipe($.uglify()) .pipe(gulp.dest(app.prdPath + 'js' )) .pipe(browserSync.stream()); }); gulp.task( 'image' , function (){ gulp.src(app.srcPath+ 'image/**/*' ) .pipe(gulp.dest(app.devPath + 'image' )) .pipe($.imagemin()) .pipe(gulp.dest(app.prdPath + 'image' )) .pipe(browserSync.stream()); }); gulp.task( 'build' ,[ 'image' , 'js' , 'less' , 'lib' , 'html' , 'json' ]); gulp.task( 'clean' , function (){ gulp.src([app.devPath,app.prdPath]) .pipe($.clean()) }); gulp.task( 'serve' ,[ 'build' ], function (){ browserSync.init({ server: "./build" , }); gulp.watch( 'bower_components/**/*' , [ 'lib' ]); gulp.watch(app.srcPath + '**/*.html' , [ 'html' ]); gulp.watch(app.srcPath + 'data/**/*.json' , [ 'json' ]); gulp.watch(app.srcPath + 'style/**/*.less' , [ 'less' ]); gulp.watch(app.srcPath + 'script/**/*.js' , [ 'js' ]); gulp.watch(app.srcPath + 'image/**/*' , [ 'image' ]); }); gulp.task( 'default' ,[ 'serve' ]) |
這是我的gulpfile.js 檔,重新打gulp 時,會刷新。
更改HTML時,也會刷新,
如果只是單獨修改 index.less 也會自動刷新
但只有在改 ,已下這2支檔案時,不會刷新,不懂為何會這樣..老師有解嗎?
@import 'property.less';
@import 'template/head.less';