Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Use rev'd asset urls in Twig and Handlebars files #446

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Desktop.ini
node_modules
**/generated/_icons.sass
npm-debug.log
yarn-error.log
5 changes: 4 additions & 1 deletion gulpfile.js/lib/webpack-multi-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions gulpfile.js/tasks/rev/rev-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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|hbs|twig|php)')

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(''))
Expand Down
10 changes: 6 additions & 4 deletions gulpfile.js/tasks/rev/rev-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.stylesheets.dest || '')

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(''))
Expand Down
7 changes: 5 additions & 2 deletions gulpfile.js/tasks/rev/update-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ var path = require('path')
// 5) Update asset references in HTML
gulp.task('update-html', function(){
var manifest = gulp.src(path.resolve(process.env.PWD, PATH_CONFIG.dest, "rev-manifest.json"))
return gulp.src(path.resolve(process.env.PWD, PATH_CONFIG.dest, PATH_CONFIG.html.dest, '**/*.html'))
.pipe(revReplace({ manifest: manifest }))
return gulp.src(path.resolve(process.env.PWD, PATH_CONFIG.dest, PATH_CONFIG.html.dest, '**/*'))
.pipe(revReplace({
manifest: manifest,
replaceInExtensions: ['.html', '.hbs', '.twig', '.json']
}))
.pipe(gulp.dest(path.resolve(process.env.PWD, PATH_CONFIG.dest, PATH_CONFIG.html.dest)))
})
Loading