postcss使用
准备
构建工具为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使用的更多相关文章
- 展望未来:使用 PostCSS 和 cssnext 书写 CSS
原文链接:A look into writing future CSS with PostCSS and cssnext 译者:nzbin 像twitter,google,bbc使用的一样,我打算看一 ...
- PostCSS深入学习: PostCSS和Sass、Stylus或LESS一起使用
如果你喜欢使用PostCSS,但又不想抛弃你最喜欢的预处理器.不用担心,你不需要作出二选一的选择,你可以把PostCSS和预处理器(Sass.Stylus或LESS)结合起来使用. 有几个PostCS ...
- 在 CSS 预编译器之后:PostCSS
提到css预编译器(css preprocessor),你可能想到Sass.Less以及Stylus.而本文要介绍的PostCSS,正是一个这样的工具:css预编译器可以做到的事,它同样可以做到. “ ...
- PostCSS一种更优雅、更简单的书写CSS方式
Sass团队创建了Compass大大提升CSSer的工作效率,你无需考虑各种浏览器前缀兼,只需要按官方文档的书写方式去写,会得到加上浏览器前缀的代码,如下: .row { @include displ ...
- [译]PostCSS介绍
PostCSS介绍 原文链接:http://www.smashingmagazine.com/2015/12/introduction-to-postcss/ 转自:http://www.zcfy.c ...
- PostCss 从0开始
PostCss 摘自 http://ju.outofmemory.cn/entry/215105 http://www.w3cplus.com/PostCSS/postcss-deep-dive-pr ...
- CSS预编译与PostCSS以及Webpack构建CSS综合方案
CSS全称Cascading Style Sheets(层叠样式表),用来为HTML添加样式,本质上是一种标记类语言.CSS前期发展非常迅速,1994年哈肯·维姆·莱首次提出CSS,1996年12月W ...
- 更便捷的css处理方式-postcss
更便捷的css处理方式-PostCSS 一般来说介绍一个东西都是要从是什么,怎么用的顺序来讲.我感觉这样很容易让大家失去兴趣,先看一下postcss能做点什么,有兴趣的话再往下看,否则可能没有耐心看下 ...
- postcss的安装与使用
我是经过公司另外一个同事推荐的这个 他是一个资深的大哥哥 我觉得我确实需要跟多的学习和成长 而且我觉得我应该听他的话 多学学新知识 最近一直在做适配的网站 会出现很多媒体查询 我发现用这个写媒体查询 ...
随机推荐
- 【Python灰帽子--黑客与逆向工程师的Python编程之道】我的学习笔记,过程.(持续更新HOT)
我的学习笔记---python灰帽子 世界让我遍体鳞伤,但伤口长出的却是翅膀. -------------------------------------------- 前言 本书是由知名安全机构Im ...
- 深入浅出新一代云网络——VPC中的那些功能与基于OpenStack Neutron的实现(一)
VPC的概念与基于vxlan的overlay实现很早就有了,标题中的"新"只是一个和传统网络的相对概念.但从前年开始,不同于以往基础网络架构的新一代SDN网络才真正越来越多的走进国 ...
- Linux下非root用户安装软件的一般流程:
1. 获取源代码,一般是wget方式,ubuntu可以使用apt-get source来获取源代码. 2. 解压源代码,一般使用tar -zxvf xxx.tar.gz即可 3. 切换到解压后的目录, ...
- 欧拉函数之HDU1286找新朋友
找新朋友 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissi ...
- Python3.5 在Ubuntu16.04上无法画图的解决方案
1. 问题由来 在使用下面的测试代码学习python时,用Pycharm画不出来图像,SPYDER3 可以画出来. 下面的代码来自:http://old.sebug.net/ # -*- coding ...
- Java读写Excel之POI超入门
转自:http://rensanning.iteye.com/blog/1538591 Apache POI 是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给J ...
- javaWeb学习总结(3)- 通过Servlet生成验证码图片(2)
一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:
- 探讨SQL Server并发处理队列数据不阻塞解决方案
前言 之前对于并发这一块确实接触的比较少,自从遇到现在的老大,每写完一块老大都会过目一下然后给出意见,期间确实收获不少,接下来有几篇会来讲解SQL Server中关于并发这一块的内容,有的是总结,有的 ...
- Linux 库文件详解
转自: http://www.cppblog.com/deane/articles/165216.html http://blog.sciencenet.cn/blog-1225851-904348. ...
- Vulkan Tutorial 07 Window surface
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Visual Studio 2017 到目前为止,我们了解到Vulkan是一个与平台特性无关联的API集合.它不能直接与窗 ...