Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDaniel Fang
3,489 PointsIs necessary the last line of code '.pipe(gulp.dest('js'))' in the minifyScripts task?
// Minify Js
gulp.task('minifyScripts', () => {
gulp.src('js/app.js')
.pipe(uglify())
.pipe(rename('app.min.js'))
.pipe(gulp.dest('js'))
});
When I run the code above with and without the line .pipe(gulp.dest('js'))
return the expect result (app.min.js) so I think this line is not necessary because the app.js file was already generated in the concat task, am I right?
2 Answers
Tom Geraghty
24,174 PointsIt's not required to have it save the newly created file in the same directory. But this will rarely be useful in production where you want to separate your source/development code from your build/production code. Typically you will provide a destination folder in your build/ or public/ or whatever you call it for production folder.
Sebastian H
19,905 PointsFrom my understanding it isn't necessary in this situation because your gulp.src path and gulp.dest path are the same. Outputting the result to the same path is most probably the default behaviour, though I haven't checked the docs to be sure.
Gulp.dest is a method used to output the result of your above pipes in a different folder. For example, I used gulp.dest to output minified scripts from a public folder into a new 'dist' (distribution) folder.
.pipe(gulp.dest('src/dist'));
The documentation on the gulp site also have great examples. Give 'em a read for more info.
https://github.com/gulpjs/gulp/blob/master/docs/API.md#gulpdestpath-options