Gulp-自動化編譯sass和pug文件


突然發現在我博客文章中,缺少這一塊的記錄,那我就補一篇吧。

gulp的環境配置和安裝:http://www.cnblogs.com/padding1015/p/7162024.html

這里就補充一篇gulpfile.js的配置,用於自動化編譯sass和pug文件用:

 1 var gulp = require('gulp');
 2 var pug = require('gulp-pug');
 3 var sass = require('gulp-sass');
 4 var rename = require('gulp-rename');
 5 var notify = require('gulp-notify');
 6 var plumber = require('gulp-plumber');
 7 
 8 var paths = {
 9   // css
10   sassWatch: 'scss/**/*.scss',
11   css: 'css',
12   // html
13   pugWatch: 'views/*.pug',
14   pugWatch2: 'views/**/*.pug',
15   html: 'html'
16 };
17 
18 gulp.task('pug', function () {
19   return gulp.src(paths.pugWatch)
20     .pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
21     .pipe(rename(function(path){
22       var filename = path.basename.split('_')[1];
23       if(!filename) {
24         return path;
25       }
26       path.basename = filename;
27       return path;
28     }))
29     .pipe(pug({
30       pretty: true
31     }))
32     .pipe(gulp.dest(paths.html))
33 });
34 
35 gulp.task('sass', function () {
36   return gulp.src(paths.sassWatch)
37     .pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
38     .pipe(sass({outputStyle: 'expanded'}))
39     .pipe(gulp.dest(paths.css))
40 });
41 
42 gulp.task('watch', ['sass'], function () {
43   gulp.watch(paths.pugWatch2, ['pug']);
44   gulp.watch(paths.sassWatch, ['sass']);
45 });
46 
47 gulp.task('default', ['watch', 'pug' ]);

沒有熱更新和瀏覽器自動刷新功能,只是適用於編譯sass和pug,並且有持續監聽、不斷開gulp的功能、還有pug改名功能。

 

 

聲明:

  請尊重博客園原創精神,轉載或使用圖片請注明:

  博主:xing.org1^

  出處:http://www.cnblogs.com/padding1015/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM