-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
59 lines (44 loc) · 1.44 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
54
55
56
57
58
59
const gulp = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const autoprefixer = require('autoprefixer');
const postcss = require('gulp-postcss');
const cleanCSS = require('gulp-clean-css');
const browserSync = require('browser-sync').create();
// Compile Sass to CSS function
function compiler() {
// Locate the SCSS files
return gulp.src('./scss/**/*.scss')
// Compile SCSS to CSS
.pipe(sass().on('error', sass.logError))
// Minify the CSS
.pipe(cleanCSS({compatibility: 'ie8'}))
// Add vendor prefixes to CSS properties
.pipe(postcss([ autoprefixer() ]))
// Save the CSS
.pipe(gulp.dest('./css'))
// Stream to all browser (doesn't reload the page)
.pipe(browserSync.stream());
}
/**
* Initiate browserSync
* Watch for changes
* Automatically compile SCSS → CSS
*/
function watch() {
// Initiate browserSync
browserSync.init({
server: {
baseDir: './'
}
})
// Automatically compile SCSS to CSS
gulp.watch('./scss/**/*.scss', compiler);
// Watch for changes in .html or .js files,
// If change detected, reload page automatically
gulp.watch('./*.html').on('change', () => browserSync.reload() );
gulp.watch('./js/**/*.js').on('change', () => browserSync.reload() );
}
// Use 'comp' to compile SCSS → CSS
exports.comp = compiler;
// Use 'watch' to watch for changes and automatic scss compilation
exports.watch = watch;