Enhance asset revving
conditional asset revving based on --production make assets.php respect new asset revving flow
This commit is contained in:
41
gulpfile.js
41
gulpfile.js
@@ -82,7 +82,9 @@ var cssTasks = function(filename) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.pipe($.rev)
|
.pipe(function () {
|
||||||
|
return $.if(enabled.rev, $.rev());
|
||||||
|
})
|
||||||
.pipe(function () {
|
.pipe(function () {
|
||||||
return $.if(enabled.maps, $.sourcemaps.write('.'));
|
return $.if(enabled.maps, $.sourcemaps.write('.'));
|
||||||
})();
|
})();
|
||||||
@@ -102,12 +104,29 @@ var jsTasks = function(filename) {
|
|||||||
})
|
})
|
||||||
.pipe($.concat, filename)
|
.pipe($.concat, filename)
|
||||||
.pipe($.uglify)
|
.pipe($.uglify)
|
||||||
.pipe($.rev)
|
.pipe(function () {
|
||||||
|
return $.if(enabled.rev, $.rev());
|
||||||
|
})
|
||||||
.pipe(function () {
|
.pipe(function () {
|
||||||
return $.if(enabled.maps, $.sourcemaps.write('.'));
|
return $.if(enabled.maps, $.sourcemaps.write('.'));
|
||||||
})();
|
})();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ### Write to Rev Manifest
|
||||||
|
// If `--production` then write the revved assets to the manifest.
|
||||||
|
var writeToManifest = function (directory) {
|
||||||
|
return lazypipe()
|
||||||
|
.pipe(gulp.dest, path.dist + directory)
|
||||||
|
.pipe(require('gulp-debug'))
|
||||||
|
.pipe($.livereload)
|
||||||
|
.pipe($.rev.manifest, revManifest, {
|
||||||
|
base: path.dist,
|
||||||
|
merge: true
|
||||||
|
})
|
||||||
|
.pipe(require('gulp-debug'))
|
||||||
|
.pipe(gulp.dest, path.dist)();
|
||||||
|
};
|
||||||
|
|
||||||
// ## Gulp Tasks
|
// ## Gulp Tasks
|
||||||
// Run `gulp -T` for a task summary
|
// Run `gulp -T` for a task summary
|
||||||
|
|
||||||
@@ -116,16 +135,11 @@ var jsTasks = function(filename) {
|
|||||||
gulp.task('styles', function() {
|
gulp.task('styles', function() {
|
||||||
var merged = merge();
|
var merged = merge();
|
||||||
manifest.forEachDependency('css', function (dep) {
|
manifest.forEachDependency('css', function (dep) {
|
||||||
merged.add(gulp.src(dep.globs, { base: path.source })
|
merged.add(gulp.src(dep.globs)
|
||||||
.pipe(cssTasks(dep.name)));
|
.pipe(cssTasks(dep.name)));
|
||||||
});
|
});
|
||||||
return merged
|
return merged
|
||||||
.pipe(gulp.dest(path.dist + 'styles'))
|
.pipe(writeToManifest('styles'));
|
||||||
.pipe($.rev.manifest(revManifest, {
|
|
||||||
base: path.dist,
|
|
||||||
merge: true
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest(path.dist));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ### Scripts
|
// ### Scripts
|
||||||
@@ -135,17 +149,12 @@ gulp.task('scripts', ['jshint'], function() {
|
|||||||
var merged = merge();
|
var merged = merge();
|
||||||
manifest.forEachDependency('js', function (dep) {
|
manifest.forEachDependency('js', function (dep) {
|
||||||
merged.add(
|
merged.add(
|
||||||
gulp.src(dep.globs, { base: path.source })
|
gulp.src(dep.globs)
|
||||||
.pipe(jsTasks(dep.name))
|
.pipe(jsTasks(dep.name))
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return merged
|
return merged
|
||||||
.pipe(gulp.dest(path.dist + 'scripts'))
|
.pipe(writeToManifest('scripts'));
|
||||||
.pipe($.rev.manifest(revManifest, {
|
|
||||||
base: path.dist,
|
|
||||||
merge: true
|
|
||||||
}))
|
|
||||||
.pipe(gulp.dest(path.dist));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ### Fonts
|
// ### Fonts
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ namespace Roots\Sage\Assets;
|
|||||||
* - You're not logged in as an administrator
|
* - You're not logged in as an administrator
|
||||||
*/
|
*/
|
||||||
function asset_path($filename) {
|
function asset_path($filename) {
|
||||||
|
$dist_path = get_template_directory_uri() . '/dist/';
|
||||||
|
|
||||||
if (WP_ENV === 'development') {
|
if (WP_ENV === 'development') {
|
||||||
return get_template_directory_uri() . '/dist/' . $filename;
|
return $dist_path . $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
$manifest_path = get_template_directory() . '/dist/assets.json';
|
$manifest_path = get_template_directory() . '/dist/assets.json';
|
||||||
@@ -30,8 +32,13 @@ function asset_path($filename) {
|
|||||||
$manifest = [];
|
$manifest = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($filename, $manifest)) {
|
$directory = dirname($filename) . '/';
|
||||||
return get_template_directory_uri() . '/dist/' . $manifest[$filename];
|
$file = basename($filename);
|
||||||
|
|
||||||
|
if (array_key_exists($file, $manifest)) {
|
||||||
|
return $dist_path . $directory . $manifest[$file];
|
||||||
|
} else {
|
||||||
|
return $dist_path . $directory . $file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user