grunt-manifest icon indicating copy to clipboard operation
grunt-manifest copied to clipboard

Really slow when using basePath

Open andrejpavlovic opened this issue 8 years ago • 1 comments

I've been using this plugin for a while, but it's been running terribly slow. Today I decided to investigate why, since adding about 800 files to a manifest shouldn't take more than a few seconds (instead it was actually taking a few minutes!)

The culprit seems to be this line of code in the plugin:

// check to see if src has been set
if (typeof file.src === "undefined") {
  grunt.fatal('Need to specify which files to include in the manifest.', 2);
}

For some reason calling typeof file.src actually causes the src array of paths to be expanded! Why? I have no idea. And since I was using basePath and my src array was full of paths that started with **/*.ext, expanding those src would essentially traverse my entire project and expand thousands of files.

Anyway, the workaround for now is to ditch basePath and use the process filter while changing src paths to include the original basePath.

So I went from:

manifest: {
  dist: {
    options: {
      basePath: 'dist/'
    },
    src: [
      '**/*.css',
      '**/*.jpg',
      '**/*.js',
      '**/*.png',
    ],
    dest: "dist/manifest.appcache"
  }
}

to

manifest: {
  dist: {
    options: {
      process: function(path) {
        // strip out the "dist/" prefix instead of relying on basePath to do it for us
        return path.substring('dist/'.length);
      }
    },
    src: [
      'dist/**/*.css',
      'dist/**/*.jpg',
      'dist/**/*.js',
      'dist/**/*.png',
    ],
    dest: "dist/manifest.appcache"
  }
}

Now it works fast!

andrejpavlovic avatar Jul 16 '15 14:07 andrejpavlovic