-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
101 lines (89 loc) · 2.47 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
97
98
99
100
101
'use strict';
// ----------------------------------------
// Imports
// ----------------------------------------
const gulp = require('gulp');
const iF = require('gulp-if');
const sass = require('gulp-sass');
const posctcss = require('gulp-postcss');
const argv = require('yargs').argv;
const notify = require('gulp-notify');
const cssnano = require('cssnano');
const sourcemaps = require('gulp-sourcemaps');
const changed = require('gulp-changed');
const browserSync = require('browser-sync').create();
// ----------------------------------------
// Private
// ----------------------------------------
const sassDest = './css/';
const sassSource = './sass/*.scss';
const sassWatch = ['./sass/**/*.scss', './prismjs-theme-sass-core/**/*.scss', './sass/_*.scss'];
const onProduction = !!argv.production;
const onWriteDest = argv.dest !== false;
// ----------------------------------------
// Public
// ----------------------------------------
gulp.task('sass', () => {
if (onProduction) {
return gulp.src(sassSource)
.pipe(sass({
indentType: 'tab',
indentWidth: 1,
linefeed: 'crlf',
outputStyle: 'expanded',
includePaths: [
'./node_modules/'
]
}))
.pipe(iF(onWriteDest, gulp.dest(sassDest)))
.pipe(posctcss([
cssnano({
preset: ['default', {
zindex: false,
autoprefixer: false,
reduceIdents: false,
discardUnused: false,
cssDeclarationSorter: false, // disable plugin
postcssCalc: false // disable plugin
}]
})
]))
.on('data', file => {
file.stem = file.stem + '.min';
})
.pipe(iF(onWriteDest, gulp.dest(sassDest)));
}
return gulp.src(sassSource)
.pipe(sourcemaps.init())
.pipe(sass({
indentType: 'tab',
indentWidth: 1,
linefeed: 'crlf',
outputStyle: 'expanded',
includePaths: [
'./node_modules/'
]
}).on('error', notify.onError({
message: 'Error: <%= error.message %>',
title: 'Error running something'
})))
.pipe(sourcemaps.write())
.pipe(changed(sassDest, { hasChanged: changed.compareContents }))
.pipe(gulp.dest(sassDest))
.pipe(browserSync.stream());
});
gulp.task('serve', () => {
browserSync.init({
server: {
baseDir: './',
directory: true
}
});
gulp.watch(sassWatch, gulp.series('sass'));
gulp.watch('./index.html').on('change', browserSync.reload);
});
// ----------------------------------------
// Public
// ----------------------------------------
gulp.task('build', gulp.series('sass'));
gulp.task('dev', gulp.series('sass', 'serve'));