-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
89 lines (78 loc) · 2.78 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
// Gulp packages ------------------------------------------------------------ //
let gulp = require('gulp');
let postcss = require('gulp-postcss');
let sass = require('gulp-sass')(require('sass'));
let rename = require('gulp-rename');
let purgecss = require('gulp-purgecss');
let sourcemaps = require('gulp-sourcemaps');
// PostCSS packages
let cssnano = require('cssnano');
let presetEnv = require('postcss-preset-env');
let lost = require('lost');
// Variables ---------------------------------------------------------------- //
// Processors
let postCssProcessors = [
lost(),
presetEnv()
];
let postCssProdProcessors = [...postCssProcessors, cssnano()];
//URLs
let paths = {
cssSource: 'src/**',
cssDest: 'dist/css',
purgeCss: ['dist/**/*.html', 'dist/**/*.js'],
excludeVendor: '!src/**/vendor/**'
};
// Tasks -------------------------------------------------------------------- //
const buildCss = function() {
return gulp.src([paths.cssSource + '/*.css', paths.excludeVendor])
.pipe(postcss(postCssProcessors))
.pipe(rename({dirname:''}))
.pipe(gulp.dest(paths.cssDest));
};
gulp.task('buildcss', buildCss);
gulp.task('buildCss', buildCss);
const buildCssProd = function() {
return gulp.src([paths.cssSource + '/*.css', paths.excludeVendor])
.pipe(postcss(postCssProdProcessors))
.pipe(purgecss({ content: paths.purgeCss }))
.pipe(rename({dirname:''}))
.pipe(gulp.dest(paths.cssDest));
};
gulp.task('buildcssprod', buildCssProd);
gulp.task('buildCssProd', buildCssProd);
const buildSass = function() {
return gulp.src([paths.cssSource + '/*.scss', paths.excludeVendor])
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(postcss(postCssProcessors))
.pipe(sourcemaps.write(''))
.pipe(rename({dirname:''}))
.pipe(gulp.dest(paths.cssDest));
};
gulp.task('buildSass', buildSass);
gulp.task('buildsass', buildSass);
const buildSassProd = function() {
return gulp.src([paths.cssSource + '/*.scss', paths.excludeVendor])
.pipe(sass().on('error', sass.logError))
.pipe(postcss(postCssProdProcessors))
.pipe(purgecss({ content: paths.purgeCss }))
.pipe(rename({dirname:''}))
.pipe(gulp.dest(paths.cssDest));
};
gulp.task('buildSassProd', buildSassProd);
gulp.task('buildsassprod', buildSassProd);
// Watch -------------------------------------------------------------------- //
const watchCss = function() {
gulp.watch(paths.cssSource + '/*.css', gulp.series(['buildCss']));
};
gulp.task('watchCss', watchCss);
gulp.task('watchcss', watchCss);
const watchSass = function() {
gulp.watch(paths.cssSource + '/*.scss', gulp.series(['buildSass']));
};
gulp.task('watchSass', watchSass);
gulp.task('watchsass', watchSass);
// Default ------------------------------------------------------------------ //
function defaultTask() { watchSass(); }
exports.default = defaultTask;