This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
100 lines (84 loc) · 2.51 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
// Gulp-starter repository
// File processing boilerplate for HTML, Sass, JS, PNG, JPEG, GIF and SVG files with Gulp.js
// https://github.com/marcop135/gulp-starter
'use strict';
// Initialize modules
// Import specific gulp API functions lets us write them below as series()
// instead of gulp.series()
const { src, dest, watch, series, parallel } = require('gulp');
// Upgrade gulp-sass to v5
// https://github.com/dlmanning/gulp-sass/tree/master#migrating-to-version-5
const sass = require('gulp-sass')(require('sass'));
// Import all the Gulp-related packages we want to use
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const browserSync = require('browser-sync');
const server = browserSync.create();
// setup the BrowserSync server
function reload(done) {
server.reload();
done();
}
function serve(done) {
server.init({
server: {
baseDir: './',
index: './index.html',
},
});
done();
}
// File paths to watch
const files = {
htmlPath: './*.html',
scssPath: 'src/scss/**/*.scss',
};
// Sass task
function scssTask() {
return (
src(files.scssPath, {
sourcemaps: true,
})
// compile SCSS to CSS
.pipe(sass.sync({ outputStyle: 'expanded' }))
// replace Node-sass auto-built charset with a useful comment
// https://stackoverflow.com/a/51886455/4027098
.pipe(
replace(
'@charset "UTF-8";',
'/*! bullframe.css v4.1.2 | MIT License | https://github.com/marcop135/bullframe.css */'
)
)
// PostCSS plugins
.pipe(postcss([autoprefixer()]))
// write pre-minifies styles
.pipe(dest('dist/css'))
// PostCSS plugins
.pipe(postcss([cssnano()]))
// rename files
.pipe(
rename({
suffix: '.min',
})
)
// put final CSS in dist folder
.pipe(
dest('dist/css', {
sourcemaps: '.',
})
)
);
}
// watch task: watch SCSS, JS, image and HTML files for changes
// If any change, run scss, js and image tasks simultaneously
// then reload via browsersync
function watchTask() {
watch([files.htmlPath, files.scssPath], series(parallel(scssTask), reload));
}
// Export the default Gulp task so it can be run
// Runs the scss, js, image and cache busting tasks simultaneously
// start local server and watch tasks
exports.default = series(parallel(scssTask), serve, watchTask);