@@ -40,58 +40,68 @@ var paths = {
4040 images: ' client/img/**/*'
4141};
4242
43+ /* Register some tasks to expose to the cli */
44+ gulp .task (' build' , gulp .series (
45+ clean,
46+ gulp .parallel (scripts, images)
47+ ));
48+ gulp .task (clean);
49+ gulp .task (watch);
50+
51+ // The default task (called when you run `gulp` from cli)
52+ gulp .task (' default' , gulp .series (' build' ));
53+
54+
55+ /* Define our tasks using plain functions */
56+
4357// Not all tasks need to use streams
4458// A gulpfile is just another node program and you can use all packages available on npm
45- gulp . task ( ' clean ' , function () {
59+ function clean () {
4660 // You can use multiple globbing patterns as you would with `gulp.src`
4761 return del ([' build' ]);
48- });
62+ }
4963
50- gulp .task (' scripts' , function () {
51- // Minify and copy all JavaScript (except vendor scripts)
52- // with sourcemaps all the way down
64+ // Copy all static images
65+ function images () {
66+ return gulp .src (paths .images )
67+ // Pass in options to the task
68+ .pipe (imagemin ({optimizationLevel: 5 }))
69+ .pipe (gulp .dest (' build/img' ));
70+ }
71+
72+ // Minify and copy all JavaScript (except vendor scripts)
73+ // with sourcemaps all the way down
74+ function scripts () {
5375 return gulp .src (paths .scripts )
5476 .pipe (sourcemaps .init ())
5577 .pipe (coffee ())
5678 .pipe (uglify ())
5779 .pipe (concat (' all.min.js' ))
5880 .pipe (sourcemaps .write ())
5981 .pipe (gulp .dest (' build/js' ));
60- });
61-
62- // Copy all static images
63- gulp .task (' images' , function () {
64- return gulp .src (paths .images )
65- // Pass in options to the task
66- .pipe (imagemin ({optimizationLevel: 5 }))
67- .pipe (gulp .dest (' build/img' ));
68- });
82+ }
6983
7084// Rerun the task when a file changes
71- gulp .task (' watch' , function () {
72- gulp .watch (paths .scripts , ' scripts' );
73- gulp .watch (paths .images , ' images' );
74- });
75-
76- gulp .task (' all' , gulp .parallel (' watch' , ' scripts' , ' images' ));
77- // The default task (called when you run `gulp` from cli)
78- gulp .task (' default' , gulp .series (' clean' , ' all' ));
85+ function watch () {
86+ gulp .watch (paths .scripts , scripts);
87+ gulp .watch (paths .images , images);
88+ }
7989```
8090
8191## Incremental Builds
8292
8393You can filter out unchanged files between runs of a task using
8494the ` gulp.src ` function's ` since ` option and ` gulp.lastRun ` :
8595``` js
86- gulp . task ( ' images ' , function () {
96+ function images () {
8797 return gulp .src (paths .images , {since: gulp .lastRun (' images' )})
8898 .pipe (imagemin ({optimizationLevel: 5 }))
8999 .pipe (gulp .dest (' build/img' ));
90- });
100+ }
91101
92- gulp . task ( ' watch ' , function () {
93- gulp .watch (paths .images , ' images' );
94- });
102+ function watch () {
103+ gulp .watch (paths .images , images);
104+ }
95105```
96106Task run times are saved in memory and are lost when gulp exits. It will only
97107save time during the ` watch ` task when running the ` images ` task
@@ -103,13 +113,13 @@ If you want to compare modification time between files instead, we recommend the
103113
104114[ gulp-newer] example:
105115``` js
106- gulp . task ( ' images ' , function () {
116+ function images () {
107117 var dest = ' build/img' ;
108118 return gulp .src (paths .images )
109119 .pipe (newer (dest)) // pass through newer images only
110120 .pipe (imagemin ({optimizationLevel: 5 }))
111121 .pipe (gulp .dest (dest));
112- });
122+ }
113123```
114124
115125If you can't simply filter out unchanged files, but need them in a later phase
@@ -119,7 +129,7 @@ of the stream, we recommend these plugins:
119129
120130[ gulp-remember] example:
121131``` js
122- gulp . task ( ' scripts ' , function () {
132+ function scripts () {
123133 return gulp .src (scriptsGlob)
124134 .pipe (cache (' scripts' )) // only pass through changed files
125135 .pipe (header (' (function () {' )) // do special things to the changed files...
@@ -128,7 +138,7 @@ gulp.task('scripts', function () {
128138 .pipe (remember (' scripts' )) // add back all files to the stream
129139 .pipe (concat (' app.js' )) // do things that require all files
130140 .pipe (gulp .dest (' public/' ))
131- });
141+ }
132142```
133143
134144## Want to test the latest and greatest?
0 commit comments