Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeThruHead committed Sep 2, 2017
1 parent 641b30f commit dac9540
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ Modify files details before the manifest is created. [more details](#hooks-optio
### `sort`

Type: `function`<br>
Default: alphebetical
Default: in dependency order

Sort files before they are passed to reduce. (unsorted array is in order of dependency graph) [more details](#hooks-options)
Sort files before they are passed to reduce. [more details](#hooks-options)

### `reduce`

Expand Down
14 changes: 1 addition & 13 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ ManifestPlugin.prototype.apply = function(compiler) {
});
}
});

// We now perform a topological sorting on the input chunks and built edges
var chunks = toposort.array(compilation.chunks, edges);

Expand Down Expand Up @@ -146,19 +147,6 @@ ManifestPlugin.prototype.apply = function(compiler) {

if (this.opts.sort) {
files = files.sort(this.opts.sort);
} else {
files = files.sort(function (fileA, fileB) {
var a = fileA.name;
var b = fileB.name;

if (a < b) {
return -1;
} else if (a > b) {
return 1;
} else {
return 0;
}
});
}

var manifest;
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
2 changes: 2 additions & 0 deletions spec/fixtures/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('./common.js');
console.log('main');
2 changes: 2 additions & 0 deletions spec/fixtures/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('./common.js');
console.log('util');
55 changes: 55 additions & 0 deletions spec/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,32 @@ describe('ManifestPlugin', function() {
});
});

it('multiple file output is dependency ordered', function(done) {
webpackCompile({
context: __dirname,
entry: {
main: './fixtures/main.js',
vendor: './fixtures/util.js'
},
plugins: [
new plugin({
seed: [],
reduce: function (manifest, file) {
return manifest.concat(file.name);
}
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'common',
filename: 'common.js'
})
]
}, {}, function(manifest) {
expect(manifest).toEqual(['common.js', 'vendor.js', 'main.js']);

done();
});
});

it('works with hashes in the filename', function(done) {
webpackCompile({
context: __dirname,
Expand Down Expand Up @@ -581,6 +607,35 @@ describe('ManifestPlugin', function() {
});
});

describe('sort', function() {
it('should allow ordering of output', function(done) {
webpackCompile({
context: __dirname,
entry: {
one: './fixtures/file.js',
two: './fixtures/file-two.js'
},
output: {
filename: '[name].js'
}
}, {
manifestOptions: {
seed: [],
sort: function(file, i) {
return 1;
},
reduce: function (manifest, file) {
return manifest.concat(file.name);
}
}
}, function(manifest, stats) {
expect(manifest).toEqual(['two.js', 'one.js']);

done();
});
});
});

describe('reduce', function() {
it('should generate custom manifest', function(done) {
webpackCompile({
Expand Down

0 comments on commit dac9540

Please sign in to comment.