Files not always ignored when dynamic

As part of Middleman Gulp Starter I’m dynmically ignoring files that are generated for production, through the external_pipeline. I do this because I rev file assets.

I have a helper method that uses a rev-manifest.json file with filenames before and after, which replaces filenames in the markup.

Example JSON file:

{
  "images/projects/main@2x.png": "images/projects/main@2x-65c6dca131.png",
  "images/sketchbook.png": "images/sketchbook-7186e78338.png",
  "images/sketchbook@2x.png": "images/sketchbook@2x-dfb248c398.png",
  "images/sublime.png": "images/sublime-4d33853f64.png",
  "images/sublime@2x.png": "images/sublime@2x-576a3756f2.png",
  "javascripts/app.js": "javascripts/app-77f18c61ff2f2d2dfecf.js",
  "stylesheets/app.css": "stylesheets/app-854d14d5d7.css"
}

As part of this I have to ignore all of the original files from Middleman or you end up with both.
This is the function after the json file has been retrieved:

# Check to see if file revving is enabled
rev_manifest = REV_MANIFEST if defined?(REV_MANIFEST)

# If file revving is enabled we need to ignore the original files
# as they will still get copied by Middleman
if rev_manifest
  rev_manifest.each do |key, value|
    ignore key
  end

  # Ignore the actual manifest file itself
  ignore 'rev-manifest.json'
end

Sometimes it works flawlessly and sometimes it doesn’t work at all and I end up with both assets
I’m wondering whether this is because this is happening in parallel somehow?

Any thoughts would be appreciated.

Hi Craig,

I am experiencing the same issue. I have been working through your Gulp Starter this week and adapting it to suit my previous Gulp setup (I do not use gulp-rev, choosing gulp-rev-all instead).

I have found that I need to run the build twice for the ignore to work correctly.

I wonder though, is this because when you build the first time the manifest file does not exist? Is the Middleman function therefore false somehow on the first build? Which may be why for me it works when running the build the second time?

Here’s my Rev task in case you’re interested:

var revisionTask = function(callback) {

  var revision = new revAll({
    dontGlobal: [/^\/favicon.ico$/, 'manifest.json'],
    dontRenameFile: [/\.html$/],
    fileNameManifest: 'manifest.json',
    fileNameVersion: 'version.json',
    hashLength: 32
  })

  return gulp.src(paths.src)

    .pipe(revision.revision())

    .pipe(gulp.dest(paths.dest))

    .pipe(revNapkin({
      // force: true,
      verbose: false
    }))

    .pipe(revision.manifestFile())

    .pipe(gulp.dest(paths.dest))

    .pipe(revision.versionFile())

    .pipe(gulp.dest(paths.dest))

}

P

Yeah that makes perfect sense that it’s not there ther first time… I wonder what I can do to work around that

I haven’t been able to come up with anything yet.

On a side issue… For some reason I cannot get the BrowserSync task to take into account the 2 second delay. I am having to manually refresh the browser. Does it work ok for you?

Yeah it works for me fine. Check out the repo I created: https://github.com/craigmdennis/middleman-gulp-starter

It’s more up to date than the screencast