-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
157 lines (142 loc) · 3.67 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
*
* GULP & SASS Starter Toolkit
* by David Rosseljong
* https://david-rosseljong.com
* https://github.com/DavidRosseljong/gulpsasstoolkit
*
* Gulp 4.0 ready.
*
* Required gulp plugins for the project.
* Comment out or delete what you don't need.
* Better yet, npm uninstall them BUT be sure
* about what you are doing.
*
*/
const { src, dest, watch, series, parallel } = require('gulp');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const browserSync = require('browser-sync').create();
//const pug = require('gulp-pug');
const image = require('gulp-image');
const prefix = require('gulp-autoprefixer');
const newer = require('gulp-newer');
const wait = require('gulp-wait');
/*
*
* The SASS task.
* It creates our compressed & prefixed css
* file including sourcemaps for the browser.
*
* Wait is included to give it time so that it
* can find all files main.sass needs. If you have
* a lot of files, occasionally it throws an error
* because it couldn't find an imported sass file.
*
*/
function sass_task() {
return src('src/sass/main.sass')
.pipe(wait(50))
.pipe(sourcemaps.init())
.pipe(sass({
errLogToConsole: true,
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(prefix())
.pipe(sourcemaps.write('/maps'))
.pipe(dest('build/css'))
.pipe(browserSync.stream());
};
/*
*
* The IMAGE task.
* Checks if images are new in the src folder,
* then compress and copy them over to the
* build folder if they are, well, new.
*
*/
function image_task() {
return src('src/img/**/*')
.pipe(newer('build/img'))
.pipe(image())
.pipe(dest('build/img'));
};
/*
*
* The PUG task.
* Prettifies our pug files after compiling.
* All files in src/pug are compiled to html,
* so that you can have index.html, about.html etc.
* Sub-directories are not compiled. They are for
* including.
*
* Set pretty to false to minify html.
*
* Please check #5 on https://gulpsasstoolkit.com/docs.html
* for the code if you want the gulp task as it is optional.
*
*/
/* Delete this comment or replace with the pug_task from the docs. */
/*
*
* The COPY task
* Copy files from node_modules or src folder
* to the build folder. E.g. Bootstrap, jQuery.
*
* Please check #4 on https://gulpsasstoolkit.com/docs.html
* for the code if you want the copy task to work as it is optional.
*
*/
/* Delete this comment or replace with the copy_task from the docs. */
/*
*
* The SERVE task.
* Initializing BrowserSync and specifying our build folder.
*
* If you don't use PUG, put your HTML files in the build folder.
*
*/
function serve_task() {
browserSync.init({
server: {
baseDir: './build'
}
});
};
/*
*
* The WATCH task.
* Watch all our files for changes, then run tasks above accordingly.
*
*/
function watch_task() {
watch('src/sass/**/*.sass', sass_task);
watch('src/img/**/*', image_task);
// Delete this if you don't use the pug_task or copy_task from the docs.
//watch('src/pug/**/**/*.pug', pug_task);
//watch('src/js/**/*.js', copy_task);
//watch('src/css/**/*.css', copy_task);
};
/*
*
* The DEFAULT task.
* This is our default task.
*
* It starts everything you need,
* so that you can start right away.
*
* More information on parallel
* and series can be found here:
*
* https://gulpjs.com/docs/en/api/parallel
* https://gulpjs.com/docs/en/api/series
*
*/
exports.default = parallel(watch_task, image_task, series(serve_task));
/*
*
* You can also export any other task as a seperate task.
* That way you can manually trigger the task by typing "gulp copy" in the terminal.
*
*/
//exports.copy = parallel(copy_task);