Skip to content

Commit

Permalink
feat: add generate option
Browse files Browse the repository at this point in the history
BREAKING CHANGE: reduce option replaced by generate option
  • Loading branch information
mastilver committed Sep 16, 2017
1 parent 34257bc commit 600bb65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ManifestPlugin(opts) {
seed: null,
filter: null,
map: null,
reduce: null,
generate: null,
}, opts || {});
}

Expand Down Expand Up @@ -150,8 +150,8 @@ ManifestPlugin.prototype.apply = function(compiler) {
});

var manifest;
if (this.opts.reduce) {
manifest = files.reduce(this.opts.reduce, seed);
if (this.opts.generate) {
manifest = this.opts.generate(seed, files);
} else {
manifest = files.reduce(function (manifest, file) {
manifest[file.name] = file.path;
Expand Down
34 changes: 19 additions & 15 deletions spec/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ describe('ManifestPlugin', function() {
});
});

describe('reduce', function() {
describe('generate', function() {
it('should generate custom manifest', function(done) {
webpackCompile({
context: __dirname,
Expand All @@ -578,12 +578,14 @@ describe('ManifestPlugin', function() {
}
}, {
manifestOptions: {
reduce: function (manifest, file) {
manifest[file.name] = {
file: file.path,
hash: file.chunk.hash
};
return manifest;
generate: function(seed, files) {
return files.reduce(function(manifest, file) {
manifest[file.name] = {
file: file.path,
hash: file.chunk.hash
};
return manifest;
}, seed);
}
}
}, function(manifest, stats) {
Expand All @@ -610,11 +612,11 @@ describe('ManifestPlugin', function() {
seed: {
key: 'value'
},
reduce: function (manifest, file) {
expect(manifest).toEqual({
generate: function (seed) {
expect(seed).toEqual({
key: 'value'
});
return manifest;
return seed;
}
}
}, function(manifest, stats) {
Expand All @@ -636,11 +638,13 @@ describe('ManifestPlugin', function() {
}, {
manifestOptions: {
seed: [],
reduce: function (manifest, file) {
return manifest.concat({
name: file.name,
file: file.path
});
generate: function (seed, files) {
return seed.concat(files.map(function(file) {
return {
name: file.name,
file: file.path
};
}));
}
}
}, function(manifest, stats) {
Expand Down

0 comments on commit 600bb65

Please sign in to comment.