Skip to content

Commit

Permalink
📦 NEW: Add Caching to JS Tasks
Browse files Browse the repository at this point in the history
Merge pull request #85 from JeremyEnglert/js-task-caching
  • Loading branch information
Ahmad Awais ⚡️ authored Jan 15, 2018
2 parents d194d35 + 1319fb0 commit db9b03f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var browserSync = require( 'browser-sync' ).create(); // Reloads browser and inj
var wpPot = require( 'gulp-wp-pot' ); // For generating the .pot file.
var sort = require( 'gulp-sort' ); // Recommended to prevent unnecessary changes in pot-file.
var cache = require( 'gulp-cache' ); // Cache files in stream for later use
var remember = require( 'gulp-remember' ); // Adds all the files it has ever seen back into the stream

/**
* Task: `browser-sync`.
Expand Down Expand Up @@ -153,7 +154,7 @@ gulp.task( 'styles', function() {
* 4. Uglifes/Minifies the JS file and generates vendors.min.js
*/
gulp.task( 'vendorsJS', function() {
return gulp.src( config.jsVendorSRC )
return gulp.src( config.jsVendorSRC, {since: gulp.lastRun( 'vendorsJS' ) } ) // Only run on changed files.
.pipe(
babel({
presets: [
Expand All @@ -165,6 +166,7 @@ gulp.task( 'vendorsJS', function() {
]
})
)
.pipe( remember( 'vendorsJS' ) ) // Bring all files back to stream
.pipe( concat( config.jsVendorFile + '.js' ) )
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems.
.pipe( gulp.dest( config.jsVendorDestination ) )
Expand Down Expand Up @@ -192,7 +194,7 @@ gulp.task( 'vendorsJS', function() {
* 4. Uglifes/Minifies the JS file and generates custom.min.js
*/
gulp.task( 'customJS', function() {
return gulp.src( config.jsCustomSRC )
return gulp.src( config.jsCustomSRC, {since: gulp.lastRun( 'customJS' ) } ) // Only run on changed files.
.pipe(
babel({
presets: [
Expand All @@ -204,6 +206,7 @@ gulp.task( 'customJS', function() {
]
})
)
.pipe( remember( 'customJS' ) ) // Bring all files back to stream
.pipe( concat( config.jsCustomFile + '.js' ) )
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems.
.pipe( gulp.dest( config.jsCustomDestination ) )
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"gulp-line-ending-corrector": "^1.0.1",
"gulp-merge-media-queries": "^0.2.1",
"gulp-notify": "^3.0.0",
"gulp-remember": "^1.0.1",
"gulp-rename": "^1.2.0",
"gulp-sass": "^3.1.0",
"gulp-sort": "^2.0.0",
Expand Down

0 comments on commit db9b03f

Please sign in to comment.