-
Notifications
You must be signed in to change notification settings - Fork 18
/
gulpfile.babel.js
128 lines (114 loc) · 3.32 KB
/
gulpfile.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import gulp from 'gulp';
import sourcemaps from 'gulp-sourcemaps';
import concat from 'gulp-concat';
import notifier from 'node-notifier';
import gutil from 'gulp-util';
import babel from 'gulp-babel';
import rename from 'gulp-rename';
import runSequence from 'run-sequence';
import stylelint from 'stylelint';
import stylefmt from 'gulp-stylefmt';
import reporter from 'postcss-reporter';
import sass from 'gulp-sass';
import less from 'gulp-less';
import postcss from 'gulp-postcss';
import autoprefixer from 'autoprefixer';
import mqpacker from 'css-mqpacker';
import csso from 'gulp-csso';
const browserSync = require('browser-sync').create();
gulp.task('js', () => {
return gulp.src([
'./js/**/*.js',
'!./js/**/*.min.js'
])
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(concat('potato.min.js'))
.pipe(babel({presets: ['es2015'], compact: false, minified: true}).on('error', function (err) {
gutil.log(gutil.colors.bold.red('Babel compile error'), err.message);
notifier.notify({title: 'Babel compile error', message: err.message});
this.emit('end');
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./js/'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('sass', () => {
return gulp.src([
'./stylesheets/sass/*.scss'
])
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded',
precision: 8
}).on('error', function (err) {
gutil.log(gutil.colors.bold.red('Sass compile error'), err.message);
notifier.notify({title: 'Sass compile error', message: err.message});
this.emit('end');
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./stylesheets/css/'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('less', () => {
return gulp.src([
'./stylesheets/less/*.less'
])
.pipe(sourcemaps.init())
.pipe(less().on('error', function (err) {
gutil.log(gutil.colors.bold.red('Less compile error'), err.message);
notifier.notify({title: 'Less compile error', message: err.message});
this.emit('end');
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./stylesheets/css/'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('postprocess', () => {
return gulp.src([
'./stylesheets/css/*.css',
'!./stylesheets/css/*.min.css'
])
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(postcss([
autoprefixer(),
mqpacker()
]))
.pipe(stylefmt())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./stylesheets/css/'))
.pipe(csso())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./stylesheets/css/'))
.pipe(browserSync.stream());
});
gulp.task('test-css', () => {
return gulp.src([
'./stylesheets/css/*.css',
'!./stylesheets/css/*.min.css'
])
.pipe(postcss([
stylelint(),
reporter({ clearReportedMessages: true })
]));
});
gulp.task('watch', () => {
gulp.watch(['./stylesheets/sass/**/*.scss'], ['sass']);
gulp.watch(['./stylesheets/less/**/*.less'], ['less']);
gulp.watch(['./js/**/*.js'], ['js']);
gulp.watch(['./examples/*.html']).on('change', browserSync.reload);
});
gulp.task('browserSync', () => {
browserSync.init({
server: {
baseDir: "./",
index: "/examples/index.html"
}
});
});
gulp.task('build-sass', function () {
runSequence('sass', ['postprocess', 'js'], 'test-css');
});
gulp.task('build-less', function () {
runSequence('less', ['postprocess', 'js'], 'test-css');
});
gulp.task('default', ['browserSync', 'watch']);