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 () {
|
||||
return $.if(enabled.maps, $.sourcemaps.write('.'));
|
||||
})();
|
||||
@@ -102,12 +104,29 @@ var jsTasks = function(filename) {
|
||||
})
|
||||
.pipe($.concat, filename)
|
||||
.pipe($.uglify)
|
||||
.pipe($.rev)
|
||||
.pipe(function () {
|
||||
return $.if(enabled.rev, $.rev());
|
||||
})
|
||||
.pipe(function () {
|
||||
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
|
||||
// Run `gulp -T` for a task summary
|
||||
|
||||
@@ -116,16 +135,11 @@ var jsTasks = function(filename) {
|
||||
gulp.task('styles', function() {
|
||||
var merged = merge();
|
||||
manifest.forEachDependency('css', function (dep) {
|
||||
merged.add(gulp.src(dep.globs, { base: path.source })
|
||||
merged.add(gulp.src(dep.globs)
|
||||
.pipe(cssTasks(dep.name)));
|
||||
});
|
||||
return merged
|
||||
.pipe(gulp.dest(path.dist + 'styles'))
|
||||
.pipe($.rev.manifest(revManifest, {
|
||||
base: path.dist,
|
||||
merge: true
|
||||
}))
|
||||
.pipe(gulp.dest(path.dist));
|
||||
.pipe(writeToManifest('styles'));
|
||||
});
|
||||
|
||||
// ### Scripts
|
||||
@@ -135,17 +149,12 @@ gulp.task('scripts', ['jshint'], function() {
|
||||
var merged = merge();
|
||||
manifest.forEachDependency('js', function (dep) {
|
||||
merged.add(
|
||||
gulp.src(dep.globs, { base: path.source })
|
||||
gulp.src(dep.globs)
|
||||
.pipe(jsTasks(dep.name))
|
||||
);
|
||||
});
|
||||
return merged
|
||||
.pipe(gulp.dest(path.dist + 'scripts'))
|
||||
.pipe($.rev.manifest(revManifest, {
|
||||
base: path.dist,
|
||||
merge: true
|
||||
}))
|
||||
.pipe(gulp.dest(path.dist));
|
||||
.pipe(writeToManifest('scripts'));
|
||||
});
|
||||
|
||||
// ### Fonts
|
||||
|
||||
@@ -18,8 +18,10 @@ namespace Roots\Sage\Assets;
|
||||
* - You're not logged in as an administrator
|
||||
*/
|
||||
function asset_path($filename) {
|
||||
$dist_path = get_template_directory_uri() . '/dist/';
|
||||
|
||||
if (WP_ENV === 'development') {
|
||||
return get_template_directory_uri() . '/dist/' . $filename;
|
||||
return $dist_path . $filename;
|
||||
}
|
||||
|
||||
$manifest_path = get_template_directory() . '/dist/assets.json';
|
||||
@@ -30,8 +32,13 @@ function asset_path($filename) {
|
||||
$manifest = [];
|
||||
}
|
||||
|
||||
if (array_key_exists($filename, $manifest)) {
|
||||
return get_template_directory_uri() . '/dist/' . $manifest[$filename];
|
||||
$directory = dirname($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