今天准备学习下gulp自动化构建工具,我想建立一个任务就能实现如下:
- 编译sass文件
- 添加浏览器前缀
- 保存即编译
- ......
gulpfile配置文件:
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
clean = require('gulp-clean'),
watch = require('gulp-watch'),
livereload = require('gulp-livereload');
// styles
gulp.task('styles', function(){
return sass('src/sass/*.scss', {style: 'expanded'})
.pipe(autoprefixer('last 2 version', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('css'));
});
//clean
gulp.task('clean', function(){
return gulp.src(['css'], {read: false})
.pipe(clean());
});
// default
gulp.task('default', ['clean'], function(){
gulp.start('styles');
});
// watch
gulp.task('watch', function(){
gulp.watch('src/sass/*.scss', ['styles']);
livereload.listen();
gulp.watch(['css/*']).on('change', livereload.changed);
});
编译时给我报了这样一个错:
E:\hp\gulp\node_modules\gulp-autoprefixer\node_modules\postcss\lib\lazy-result.js:152
this.processing = new Promise(function (resolve, reject) {
^
ReferenceError: Promise is not defined
at LazyResult.async (E:\hp\gulp\node_modules\gulp-autoprefixer\node_modules\postcss\lib\lazy-res
ult.js:152:31)
at LazyResult.then (E:\hp\gulp\node_modules\gulp-autoprefixer\node_modules\postcss\lib\lazy-resu
lt.js:75:21)
at DestroyableTransform._transform (E:\hp\gulp\node_modules\gulp-autoprefixer\index.js:28:13)
at DestroyableTransform.Transform._read (E:\hp\gulp\node_modules\gulp-autoprefixer\node_modules\
through2\node_modules\readable-stream\lib\_stream_transform.js:172:10)
at DestroyableTransform.Transform._write (E:\hp\gulp\node_modules\gulp-autoprefixer\node_modules
\through2\node_modules\readable-stream\lib\_stream_transform.js:160:12)
at doWrite (E:\hp\gulp\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\readabl
e-stream\lib\_stream_writable.js:326:12)
at writeOrBuffer (E:\hp\gulp\node_modules\gulp-autoprefixer\node_modules\through2\node_modules\r
eadable-stream\lib\_stream_writable.js:312:5)
at DestroyableTransform.Writable.write (E:\hp\gulp\node_modules\gulp-autoprefixer\node_modules\t
hrough2\node_modules\readable-stream\lib\_stream_writable.js:239:11)
at DestroyableTransform.ondata (E:\hp\gulp\node_modules\gulp-sourcemaps\node_modules\through2\no
de_modules\readable-stream\lib\_stream_readable.js:574:20)
at DestroyableTransform.emit (events.js:95:17)
各种Google后终于找到了解决方法:
因为我的node.js版本是0.12.5,需要将node.js的版本升级到4.1
问题的issue地址