-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
100 lines (85 loc) · 2.93 KB
/
index.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
'use strict';
var argv = require('yargs').argv,
autoprefixer = require('gulp-autoprefixer'),
browserSync = require('browser-sync'),
cleanCSS = require('gulp-clean-css'),
gulpif = require('gulp-if'),
sass = require('gulp-sass'),
sassLint = require('gulp-sass-lint'),
sassGlob = require('gulp-sass-glob'),
sourceMaps = require('gulp-sourcemaps'),
wait = require('gulp-wait');
// CSS minification is disabled by default, you can enable with --minify.
var minify = (typeof argv.minify !== 'undefined');
// Sourcemaps are enabled by default, you can disable them with --no-sourcemaps.
var noSourceMaps = (typeof argv['no-sourcemaps'] !== 'undefined');
// BrowserSync is enabled by default when runing `gulp watch`, you can disable it with --no-browsersync.
var noBrowserSync = (typeof argv['no-browsersync'] !== 'undefined');
// You may specify a delay in milliseconds for BrowserSync so that it doesn't
// get triggered right away after compiling sass files.
var browserSyncDelay = (!noBrowserSync && typeof argv['browsersync-delay'] !== 'undefined') ? argv['browsersync-delay'] : 0;
// Production mode is the functional equivalent of specifying the following:
// --minify --no-sourcemaps --no-browsersync
// specifying the --production argument overrides any individual argument.
var production = typeof argv.production !== 'undefined';
if (production) {
minify = noSourceMaps = noBrowserSync = true;
}
// Define paths in the filesystem for easy access.
var paths = {
'css': 'css',
'scss': ['scss/**/*.scss', 'sass/**/*.scss']
};
module.exports = function (gulp) {
/**
* Task: Run the BrowserSync server.
*/
gulp.task('browsersync', function() {
browserSync.init();
});
/**
* Task: Compiles Sass files to CSS.
*/
gulp.task('sass', function () {
return gulp.src(paths.scss)
.pipe(gulpif(!noSourceMaps, sourceMaps.init()))
.pipe(sassGlob().on('error', sass.logError))
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({cascade: false}))
.pipe(gulpif(minify, cleanCSS({compatibility: 'ie8'})))
.pipe(gulpif(!noSourceMaps, sourceMaps.write('')))
.pipe(gulp.dest(paths.css))
.pipe(gulpif(browserSyncDelay, wait(browserSyncDelay)))
.pipe(browserSync.stream());
});
/**
* Task: Lints Sass files.
*/
gulp.task('sass:lint', function () {
return gulp.src(paths.scss)
.pipe(sassLint({
files: {ignore: 'scss/base/_normalize.scss'}
}))
.pipe(sassLint.format())
});
/**
* Task: Build.
*/
gulp.task('build', gulp.series('sass:lint', 'sass'));
/**
* Task: Default —> Build.
*/
gulp.task('default', gulp.series('build'));
/**
* Task: Watch.
*
* Continuously watches for changes in Sass and JS files and runs tasks
* accordingly.
*/
gulp.task('watch', function () {
if (!noBrowserSync) {
browserSync.init();
}
gulp.watch(paths.scss, gulp.series('build'));
});
};