-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
53 lines (46 loc) · 1.4 KB
/
gulpfile.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
// Packages node
const gulp = require('gulp')
const clean = require('gulp-clean')
const plumber = require('gulp-plumber')
const notify = require('gulp-notify')
const sass = require('gulp-sass')
const sourcemaps = require('gulp-sourcemaps')
const postcss = require('gulp-postcss')
const autoprefixer = require('autoprefixer')
const mq = require('css-mqpacker')
// Paths
const pathCss = 'css'
const confPostCss = [
autoprefixer({ browsers: ['last 2 versions', '> 1%', 'Firefox ESR', 'Safari >=7', 'ie >= 9'] }),
mq()
]
// Compilation SCSS => CSS
gulp.task('scss', _ => (
gulp.src(`${pathCss}/*.scss`)
.pipe(plumber({
errorHandler (err) {
notify.onError({
title: 'Gulp Sass',
message: 'Error: <%= error.message %>',
sound: 'Beep'
})(err)
this.emit('end')
}
}))
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'expanded' }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(pathCss))
))
// Watchers
gulp.task('watch', ['scss'], _ => gulp.watch(`${pathCss}/**/*.scss`, ['scss']))
// On enlève le fichier map pour la prod
gulp.task('clean', _ => gulp.src(`${pathCss}/*.map`, { read: false }).pipe(clean()))
// Production
gulp.task('prod', ['clean'], _ => {
gulp.src(`${pathCss}/*.scss`)
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(postcss(confPostCss))
.pipe(gulp.dest(pathCss))
})
gulp.task('default', ['watch'])