-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
96 lines (69 loc) · 2.02 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
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
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var cleanCSS = require('gulp-clean-css');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
// var browserSync = require('browser-sync').create();
var input = ['assets/sass/*.scss', 'assets/sass/**/*.scss'];
var output = 'assets/css';
var sassOptions = {
errLogToConsole: true,
outputStyle: 'expanded'
};
var autoprefixerOptions = {
browsers: ['last 2 versions', '> 5%', 'Firefox ESR']
};
// Compile sass
gulp.task('sass', function () {
gulp
// Find all `.sass` files from the `stylesheets/` folder
.src(input)
.pipe(sourcemaps.init())
// Run Sass on those files
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(sourcemaps.write('../sourcemaps'))
// Write the resulting CSS in the output folder
.pipe(gulp.dest(output))
/*.pipe(browserSync.stream())*/;
});
// Minify css
gulp.task('minify-css', function() {
gulp
.src([
'assets/**/*.css',
'!assets/**/*.min.css'
])
.pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('assets/'));
});
// Minify js
gulp.task('minify-js', function() {
gulp
.src([
'assets/**/*.js',
'!assets/**/*.min.js'
])
.pipe(uglify().on('error', gutil.log))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('assets/'));
});
gulp.task('watch', function() {
gulp
// Watch the input folder for change,
// and run `sass` task when something happens
.watch(input, ['sass'])
// When there is a change,
// log a message in the console
.on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
// gulp.watch(['assets/**/*.css', '!assets/**/*.min.css'], ['minify-css']);
//
// gulp.watch(['assets/**/*.js', '!assets/**/*.min.js'], ['minify-js']);
});
gulp.task('default', ['sass', 'watch']);