准备

构建工具为Gulp
基于PostCSS
PostCSS插件 CSSNext 用下一代CSS书写方式兼容现在浏览器
PostCSS插件 Autoprefixer 为CSS补全浏览器前缀
PostCSS插件 CSS Grace 让CSS兼容旧版IE

package.json

"devDependencies": {
"autoprefixer": "^7.1.1",
"browser-sync": "^2.18.8",
"compass": "^0.1.1",
"gulp": "^3.9.1",
"gulp-changed": "^2.0.0",
"gulp-compass": "^2.1.0",
"gulp-html-beautify": "^1.0.1",
"gulp-load-plugins": "^1.5.0",
"gulp-plumber": "^1.1.0",
"gulp-postcss": "^7.0.0",
"gulp-pug": "^3.3.0",
"gulp-sass": "^3.1.0",
"gulp-sourcemaps": "^2.6.0",
"precss": "^1.4.0",
"pug": "^2.0.0-beta.12",
"cssgrace": "^3.0.0"
},
"dependencies": {
"express": "^4.15.2",
"pug": "^2.0.0-beta.12"
}

  

gulpfile.js

var gulp        = require("gulp");
var plugins = require("gulp-load-plugins")();
var browserSync = require("browser-sync").create();
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var cssgrace = require('cssgrace');
// /*执行命令行工具*/
// var exec = require('child_process').exec;
// exec("node server/index.js", function(err, stdout, stderr) {
// var status = err ? -1 : 1,
// cmd_result = err ? stderr : stdout;
// // 可以获取到错误信息、标准输出和标准错误输出,接下来继续处理吧
// }); //编译pug
gulp.task("pug:compile",function() {
gulp.src("src/*.pug")
.pipe(plugins.plumber())
.pipe(plugins.changed("./build/",{extension:".html"}))
.pipe(plugins.pug({
pretty:"\t"
}))
.pipe(plugins.htmlBeautify({
indent_size:4,
indent_char:" "
}))
.pipe(gulp.dest("./build/"))
})
//监控pug
gulp.task("pug:watch",function() {
gulp.watch("src/*.pug",["pug:compile"])
})
//编译pug-templates
gulp.task('pug-templates:compile',function(){
gulp.src('src/*.pug')
.pipe(plugins.plumber())
.pipe(plugins.pug({
pretty: '\t'
}))
.pipe(plugins.htmlBeautify({
indent_size: 4,
indent_char: ' ',
unformatted: true,
extra_liners: []
}))
.pipe(gulp.dest('./build/'));
});
//监控pug-templates
gulp.task('pug-templates:watch',function(){
gulp.watch('src/templates/*.pug',['pug-templates:compile']);
}); /*编译compass*/
gulp.task("compass:compile",function() {
gulp.src("src/sass/sass_parts/*.scss")
.pipe(plugins.plumber())
.pipe(plugins.compass({
config_file:"./src/sass/config.rb",
sass:"src/sass/sass_parts",
css:"src/sass/stylesheets"
}))
.pipe(sourcemaps.init())
.pipe( postcss([ require('precss'), require('autoprefixer'), cssgrace ]) )
.pipe( sourcemaps.write('.') )
.pipe(gulp.dest("./build/css"));
})
//监控compass sass
gulp.task("compass:watch",function() {
gulp.watch("src/sass/sass_parts/**/*.scss",["compass:compile"]);
});
//browser-sync
gulp.task("browser-sync",function() {
var files = [
"./build/*.html",
"./build/**/*.css",
"./build/**/*.js"
];
browserSync.init(files,{
server:{
baseDir:"./build"
},
port:3061
})
})
gulp.task("default",["pug:watch","pug-templates:watch","compass:watch","browser-sync"])

 

src结构目录

 

postcss使用的更多相关文章

  1. 展望未来:使用 PostCSS 和 cssnext 书写 CSS

    原文链接:A look into writing future CSS with PostCSS and cssnext 译者:nzbin 像twitter,google,bbc使用的一样,我打算看一 ...

  2. PostCSS深入学习: PostCSS和Sass、Stylus或LESS一起使用

    如果你喜欢使用PostCSS,但又不想抛弃你最喜欢的预处理器.不用担心,你不需要作出二选一的选择,你可以把PostCSS和预处理器(Sass.Stylus或LESS)结合起来使用. 有几个PostCS ...

  3. 在 CSS 预编译器之后:PostCSS

    提到css预编译器(css preprocessor),你可能想到Sass.Less以及Stylus.而本文要介绍的PostCSS,正是一个这样的工具:css预编译器可以做到的事,它同样可以做到. “ ...

  4. PostCSS一种更优雅、更简单的书写CSS方式

    Sass团队创建了Compass大大提升CSSer的工作效率,你无需考虑各种浏览器前缀兼,只需要按官方文档的书写方式去写,会得到加上浏览器前缀的代码,如下: .row { @include displ ...

  5. [译]PostCSS介绍

    PostCSS介绍 原文链接:http://www.smashingmagazine.com/2015/12/introduction-to-postcss/ 转自:http://www.zcfy.c ...

  6. PostCss 从0开始

    PostCss 摘自 http://ju.outofmemory.cn/entry/215105 http://www.w3cplus.com/PostCSS/postcss-deep-dive-pr ...

  7. CSS预编译与PostCSS以及Webpack构建CSS综合方案

    CSS全称Cascading Style Sheets(层叠样式表),用来为HTML添加样式,本质上是一种标记类语言.CSS前期发展非常迅速,1994年哈肯·维姆·莱首次提出CSS,1996年12月W ...

  8. 更便捷的css处理方式-postcss

    更便捷的css处理方式-PostCSS 一般来说介绍一个东西都是要从是什么,怎么用的顺序来讲.我感觉这样很容易让大家失去兴趣,先看一下postcss能做点什么,有兴趣的话再往下看,否则可能没有耐心看下 ...

  9. postcss的安装与使用

    我是经过公司另外一个同事推荐的这个 他是一个资深的大哥哥  我觉得我确实需要跟多的学习和成长 而且我觉得我应该听他的话 多学学新知识 最近一直在做适配的网站 会出现很多媒体查询 我发现用这个写媒体查询 ...

随机推荐

  1. NancyFx 2.0的开源框架的使用-Forms

    同样的像前面2篇博文一样,每个项目的开始基本都是建个空的Web项目 在NuGet库中安装以下几个NuGet包 Nancy Nancy.Authentication.Forms Nancy.Hostin ...

  2. JavaScript开发中几个常用知识点总结

    最近在做项目的时候自己写了一些JavaScipt代码,于是自己又进行简单的查阅资料整理了一下,发现了如下几个比较有用的知识点: 1.三种声明函数的方式 2.jQuery $(document).rea ...

  3. Android 模块化探索与实践

    首发于<程序员>杂志五月刊 一.前言 万维网发明人 Tim Berners-Lee 谈到设计原理时说过:"简单性和模块化是软件工程的基石:分布式和容错性是互联网的生命." ...

  4. jeesz分布式架构集成阿里云oss存储

      1. 服务接口定义 /**  * 文件上传  1:头像 2:显示图片 3:个人封面  :4:基础图片   * @param request  * @param response  * @param ...

  5. Java调用IDL方法总结

    Java调用IDL方法总结 Java调用IDL程序,需要先在java中加载IDL的java包(javaidlb.jar),该包不需要下载,在IDL的安装目录中可以直接找到(C:\Program Fil ...

  6. Centos5搭建vsftpd服务

    更换镜像源 由于centos5已经历史久远,内置的镜像源已经不能用.看: 因此,我手工更换了阿里云的源.(ps:我本来是想用网易的源,但不知为什么,这个源在安装vsftpd时提示http 404错误) ...

  7. Python爬虫02——贴吧图片爬虫V2.0

    Python小爬虫——贴吧图片爬虫V2.0 贴吧图片爬虫进阶:在上次的第一个小爬虫过后,用了几次发现每爬一个帖子,都要自己手动输入帖子链接,WTF这程序简直反人类!不行了不行了得改进改进. 思路: 贴 ...

  8. MySql学习笔记(五) —— 存储过程

    存储过程是MySql 5支持的特性,它是一组为了完成特定功能的SQL语句集,经过编译之后存储在数据库中,当需要使用该组SQL语句时用户只需要通过指定储存过程的名字并给定参数就可以调用执行它了,简而言之 ...

  9. How to use data analysis for machine learning (example, part 1)

    In my last article, I stated that for practitioners (as opposed to theorists), the real prerequisite ...

  10. hdu_A Walk Through the Forest ——迪杰特斯拉+dfs

    A Walk Through the Forest Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/ ...