From 10658fae1a6a665fa47620f4329b6eaa485fb831 Mon Sep 17 00:00:00 2001 From: Eli Van Zoeren Date: Sun, 4 Jun 2017 19:18:34 -0400 Subject: [PATCH 1/3] Add an additional `webroot` path setting, which is used by the rev tasks to generate correct asset URIs when the main `dest` is different from the final public folder. --- README.md | 2 ++ gulpfile.js/lib/webpack-multi-config.js | 5 ++++- gulpfile.js/tasks/rev/rev-assets.js | 8 +++++--- gulpfile.js/tasks/rev/rev-css.js | 10 ++++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d1f96b4d3..59b20351d 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,8 @@ File structure is configued through a **config/path-config.json** file. This fil This file specifies the `src` and `dest` root directories, and `src` and `dest` for each task, relative to the configured root. +If the public webroot directory is different from the main `dest` directory, you may also specify the `webroot` setting, with the name of the subdirectory, e.g. `public_html`. + A minimal setup might look someting like this: ```json diff --git a/gulpfile.js/lib/webpack-multi-config.js b/gulpfile.js/lib/webpack-multi-config.js index 17922b71a..726402d08 100644 --- a/gulpfile.js/lib/webpack-multi-config.js +++ b/gulpfile.js/lib/webpack-multi-config.js @@ -75,7 +75,10 @@ module.exports = function (env) { if (env === 'production') { if (rev) { - webpackConfig.plugins.push(new webpackManifest(PATH_CONFIG.javascripts.dest, PATH_CONFIG.dest)) + var srcPath = PATH_CONFIG.rootPath ? + path.relative(PATH_CONFIG.rootPath, PATH_CONFIG.javascripts.dest) : + PATH_CONFIG.javascripts.dest + webpackConfig.plugins.push(new webpackManifest(srcPath, PATH_CONFIG.dest)) } const uglifyConfig = TASK_CONFIG.javascripts.production.uglifyJsPlugin diff --git a/gulpfile.js/tasks/rev/rev-assets.js b/gulpfile.js/tasks/rev/rev-assets.js index 12efbb844..59f1614f5 100644 --- a/gulpfile.js/tasks/rev/rev-assets.js +++ b/gulpfile.js/tasks/rev/rev-assets.js @@ -5,12 +5,14 @@ var revNapkin = require('gulp-rev-napkin'); // 1) Add md5 hashes to assets referenced by CSS and JS files gulp.task('rev-assets', function() { + var srcPath = path.resolve(process.env.PWD, PATH_CONFIG.dest, PATH_CONFIG.rootPath || '') + // Ignore files that may reference assets. We'll rev them next. - var ignoreThese = '!' + path.resolve(process.env.PWD, PATH_CONFIG.dest,'**/*+(css|js|map|json|html)') + var ignoreThese = '!' + path.resolve(srcPath, '**/*+(css|js|map|json|html)') - return gulp.src([path.resolve(process.env.PWD, PATH_CONFIG.dest,'**/*'), ignoreThese]) + return gulp.src([path.resolve(srcPath, '**/*'), ignoreThese]) .pipe(rev()) - .pipe(gulp.dest(PATH_CONFIG.dest)) + .pipe(gulp.dest(srcPath)) .pipe(revNapkin({ verbose: false, force: true })) .pipe(rev.manifest(path.resolve(process.env.PWD, PATH_CONFIG.dest, 'rev-manifest.json'), {merge: true})) .pipe(gulp.dest('')) diff --git a/gulpfile.js/tasks/rev/rev-css.js b/gulpfile.js/tasks/rev/rev-css.js index b887fa87c..f15dffee5 100644 --- a/gulpfile.js/tasks/rev/rev-css.js +++ b/gulpfile.js/tasks/rev/rev-css.js @@ -3,12 +3,14 @@ var path = require('path') var rev = require('gulp-rev') var revNapkin = require('gulp-rev-napkin') -// 4) Rev and compress CSS and JS files (this is done after assets, so that if a +// 4) Rev and compress CSS files (this is done after assets, so that if a // referenced asset hash changes, the parent hash will change as well -gulp.task('rev-css', function(){ - return gulp.src(path.resolve(process.env.PWD, PATH_CONFIG.dest,'**/*.css')) +gulp.task('rev-css', function() { + var srcPath = path.resolve(process.env.PWD, PATH_CONFIG.dest, PATH_CONFIG.rootPath || '') + + return gulp.src(path.resolve(srcPath, '**/*.css')) .pipe(rev()) - .pipe(gulp.dest(PATH_CONFIG.dest)) + .pipe(gulp.dest(srcPath)) .pipe(revNapkin({verbose: false, force: true})) .pipe(rev.manifest(path.resolve(process.env.PWD, PATH_CONFIG.dest, 'rev-manifest.json'), {merge: true})) .pipe(gulp.dest('')) From a3fc4c3dbc2dc5f7ce6dd72fb4a9b8c51479f480 Mon Sep 17 00:00:00 2001 From: Eli Van Zoeren Date: Fri, 20 Oct 2017 11:49:31 -0400 Subject: [PATCH 2/3] Update rev task for better compatibility with WordPress theme structure --- gulpfile.js/tasks/rev/rev-assets.js | 2 +- gulpfile.js/tasks/rev/rev-css.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gulpfile.js/tasks/rev/rev-assets.js b/gulpfile.js/tasks/rev/rev-assets.js index 59f1614f5..b4f9fce72 100644 --- a/gulpfile.js/tasks/rev/rev-assets.js +++ b/gulpfile.js/tasks/rev/rev-assets.js @@ -8,7 +8,7 @@ gulp.task('rev-assets', function() { var srcPath = path.resolve(process.env.PWD, PATH_CONFIG.dest, PATH_CONFIG.rootPath || '') // Ignore files that may reference assets. We'll rev them next. - var ignoreThese = '!' + path.resolve(srcPath, '**/*+(css|js|map|json|html)') + var ignoreThese = '!' + path.resolve(srcPath, '**/*+(css|js|map|json|html|php)') return gulp.src([path.resolve(srcPath, '**/*'), ignoreThese]) .pipe(rev()) diff --git a/gulpfile.js/tasks/rev/rev-css.js b/gulpfile.js/tasks/rev/rev-css.js index f15dffee5..6dec9c94b 100644 --- a/gulpfile.js/tasks/rev/rev-css.js +++ b/gulpfile.js/tasks/rev/rev-css.js @@ -6,7 +6,7 @@ var revNapkin = require('gulp-rev-napkin') // 4) Rev and compress CSS files (this is done after assets, so that if a // referenced asset hash changes, the parent hash will change as well gulp.task('rev-css', function() { - var srcPath = path.resolve(process.env.PWD, PATH_CONFIG.dest, PATH_CONFIG.rootPath || '') + var srcPath = path.resolve(process.env.PWD, PATH_CONFIG.dest, PATH_CONFIG.stylesheets.dest || '') return gulp.src(path.resolve(srcPath, '**/*.css')) .pipe(rev()) From 43a229d9501cfa174f63a126fb5a3d102e9aad8e Mon Sep 17 00:00:00 2001 From: Eli Van Zoeren Date: Tue, 19 Dec 2017 11:07:53 -0500 Subject: [PATCH 3/3] Change "rootPath" to "webroot" --- gulpfile.js/lib/webpack-multi-config.js | 4 ++-- gulpfile.js/tasks/rev/rev-assets.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gulpfile.js/lib/webpack-multi-config.js b/gulpfile.js/lib/webpack-multi-config.js index 726402d08..98b98a0a3 100644 --- a/gulpfile.js/lib/webpack-multi-config.js +++ b/gulpfile.js/lib/webpack-multi-config.js @@ -75,8 +75,8 @@ module.exports = function (env) { if (env === 'production') { if (rev) { - var srcPath = PATH_CONFIG.rootPath ? - path.relative(PATH_CONFIG.rootPath, PATH_CONFIG.javascripts.dest) : + var srcPath = PATH_CONFIG.webroot ? + path.relative(PATH_CONFIG.webroot, PATH_CONFIG.javascripts.dest) : PATH_CONFIG.javascripts.dest webpackConfig.plugins.push(new webpackManifest(srcPath, PATH_CONFIG.dest)) } diff --git a/gulpfile.js/tasks/rev/rev-assets.js b/gulpfile.js/tasks/rev/rev-assets.js index b4f9fce72..2bcf8742e 100644 --- a/gulpfile.js/tasks/rev/rev-assets.js +++ b/gulpfile.js/tasks/rev/rev-assets.js @@ -5,10 +5,10 @@ var revNapkin = require('gulp-rev-napkin'); // 1) Add md5 hashes to assets referenced by CSS and JS files gulp.task('rev-assets', function() { - var srcPath = path.resolve(process.env.PWD, PATH_CONFIG.dest, PATH_CONFIG.rootPath || '') + var srcPath = path.resolve(process.env.PWD, PATH_CONFIG.dest, PATH_CONFIG.webroot || '') // Ignore files that may reference assets. We'll rev them next. - var ignoreThese = '!' + path.resolve(srcPath, '**/*+(css|js|map|json|html|php)') + var ignoreThese = '!' + path.resolve(srcPath, '**/*+(css|js|map|json|html)') return gulp.src([path.resolve(srcPath, '**/*'), ignoreThese]) .pipe(rev())