Gulp-自动化编译sass和pug文件
突然发现在我博客文章中,缺少这一块的记录,那我就补一篇吧。
gulp的环境配置和安装:http://www.cnblogs.com/padding1015/p/7162024.html
这里就补充一篇gulpfile.js的配置,用于自动化编译sass和pug文件用:
var gulp = require('gulp');
var pug = require('gulp-pug');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var notify = require('gulp-notify');
var plumber = require('gulp-plumber');
var paths = {
// css
sassWatch: 'scss/**/*.scss',
css: 'css',
// html
pugWatch: 'views/*.pug',
pugWatch2: 'views/**/*.pug',
html: 'html'
};
gulp.task('pug', function () {
return gulp.src(paths.pugWatch)
.pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
.pipe(rename(function(path){
var filename = path.basename.split('_')[1];
if(!filename) {
return path;
}
path.basename = filename;
return path;
}))
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest(paths.html))
});
gulp.task('sass', function () {
return gulp.src(paths.sassWatch)
.pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
.pipe(sass({outputStyle: 'expanded'}))
.pipe(gulp.dest(paths.css))
});
gulp.task('watch', ['sass'], function () {
gulp.watch(paths.pugWatch2, ['pug']);
gulp.watch(paths.sassWatch, ['sass']);
});
gulp.task('default', ['watch', 'pug' ]);
没有热更新和浏览器自动刷新功能,只是适用于编译sass和pug,并且有持续监听、不断开gulp的功能、还有pug改名功能。
声明:
请尊重博客园原创精神,转载或使用图片请注明:
博主:xing.org1^
出处:http://www.cnblogs.com/padding1015/
Gulp-自动化编译sass和pug文件的更多相关文章
- webstorm和intellij idea下如何自动编译sass和scss文件
webstorm和intellij idea下如何自动编译sass和scss文件 https://segmentfault.com/a/1190000008996504 https://www.jia ...
- Gulp如何编译sass
Gulp 是一个自动化工具,前端开发者可以使用它来处理常见任务: 1.搭建web服务器 2.文件保存时自动重载浏览器 3.使用预处理器如Sass.LESS 4.优化资源,比如压缩CSS.JavaScr ...
- gulp编译sass
前言:前段时间学习了sass语法,但是一直用的是"考拉"这个软件工具将我写的sass代码编译成css,然后再引用到项目里面去的,随着对sass的更加深入的了解,我开始尝试着将sas ...
- 使用gulp编译sass
之前写了一篇在ruby环境下如何编译sass的文章:<css预处理器sass使用教程(多图预警)>,随着现在前端构建工具的兴起,也学着使用这些工具来编译sass.webpack存在一个CS ...
- nodejs编译sass模块包 node-compass,与gulp包gulp-sass使用方法
简介:node express或者就是node项目中,要自动编译sass方法很多,比如gulp 比如考拉,比如今天我想说的这个包node-compass. 编译sass的三种方法: 前提条件: 都需要 ...
- 前端自动化之sass实时编译及自动刷新浏览器
gulp livereload实现sass实时编译及浏览器自动刷新 首先gulp是基于Node的,所以确保你已经安装 node.js,在Nodejs官方网站下载跟自己操作系统相对应的安装包. 先说一下 ...
- 使用 gulp 编译 Sass
无论是 node-sass 还是 ruby-sass 使用 npm 安装都非常的慢,甚至会装不上.及其不利于团队协作.建议使用 less 作为 css 预处理器. 如果因为 less 不支持自定义函数 ...
- 项目使用gulp的配置编译sass笔记
Node环境 通过 node.js 网站下载了安装包进行安装 node.js, npm也会一起安装 node --version # 查看node.js版本 npm --version #查看npm版 ...
- Visual Studio 2017中使用gulp编译sass/scss
在Visual Studio 2017中使用gulp编译sass/scss文件 需要的环境:Visual Studio 2017.Node.js.npm 在vs2017中 [视图]-[其他窗口]-[任 ...
随机推荐
- Maven服务器
Maven私服仓库管理: Nexus 3.0 使用nexus3.X搭建maven私服在Centos7环境中-详细教程
- mac qq怎么删除全部聊天记录
找到 ./Users/user/Library/Containers/com.tencent.qq/ 删除com.tencent.qq文件夹就行.
- ★Linux桌面系统技巧(作为客户端)
[安装chrome浏览器]* 下载(已下载完成):32位:wget https://dl.google.com/linux/direct/google-chrome-stable_current_i3 ...
- [poj3565]Ants
[poj3565]Ants 标签(空格分隔):二分图 描述 Young naturalist Bill studies ants in school. His ants feed on plant-l ...
- Windows下nexus-3.*搭建Maven私服
1.下载 从官网下载https://help.sonatype.com/display/NXRM3/Download 选择Windows archive https://download.sonaty ...
- EmguCV 绘画图形
1.Image类中绘图常用函数列表 实践验证 ///初始化图片 private void Form1_Load(object sender, EventArgs e) { oldpic = new E ...
- 洛谷P3796 - 【模板】AC自动机(加强版)
原题链接 Description 模板题啦~ Code //[模板]AC自动机(加强版) #include <cstdio> #include <cstring> int co ...
- 利用 jQuery 来验证密码两次输入是否相同
html <div class="row"> <div class="panel panel-info"> <div class= ...
- 编译、裁剪、安装、删除 Ubuntu内核和模块管理
一.下载最新内核文件 地址:http://www.kernel.org,一般下载Full Source版本. 下载完毕后,放到任意文件夹中,使用命令: tar jxvf linux-x.x.x.tar ...
- configure: error: xml2-config not found. Please check your libxml2 installation
安装php时的报错 checking libxml2 install dir... nochecking for xml2-config path... configure: error: xml2- ...