Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass entrypoints param to generate function #192

Merged
merged 2 commits into from
Sep 23, 2019
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ Sort files before they are passed to `generate`. [FileDescriptor typings](#filed

### `options.generate`

Type: `Function(Object, FileDescriptor): Object`<br>
Default: `(seed, files) => files.reduce((manifest, {name, path}) => ({...manifest, [name]: path}), seed)`
Type: `Function(Object, FileDescriptor, string[]): Object`<br>
Default: `(seed, files, entrypoints) => files.reduce((manifest, {name, path}) => ({...manifest, [name]: path}), seed)`

Create the manifest. It can return anything as long as it's serialisable by `JSON.stringify`. [FileDescriptor typings](#filedescriptor)

Expand Down
13 changes: 12 additions & 1 deletion lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,18 @@ ManifestPlugin.prototype.apply = function(compiler) {

var manifest;
if (this.opts.generate) {
manifest = this.opts.generate(seed, files);
const entrypointsArray = Array.from(
compilation.entrypoints instanceof Map ?
// Webpack 4+
compilation.entrypoints.entries() :
// Webpack 3
Object.entries(compilation.entrypoints)
);
const entrypoints = entrypointsArray.reduce((e, [name, entrypoint]) => ({
...e,
[name]: entrypoint.getFiles()
}), {});
manifest = this.opts.generate(seed, files, entrypoints);
} else {
manifest = files.reduce(function (manifest, file) {
manifest[file.name] = file.path;
Expand Down
38 changes: 38 additions & 0 deletions spec/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,44 @@ describe('ManifestPlugin', function() {
});
});

it('should generate manifest with "entrypoints" key', done => {
webpackCompile({
context: __dirname,
entry: {
one: './fixtures/file.js',
two: './fixtures/file-two.js'
}
},
{
manifestOptions: {
generate: (seed, files, entrypoints) => {
const manifestFiles = files.reduce((manifest, { name, path }) => ({
...manifest,
[name]: path
}), seed);
return {
files: manifestFiles,
entrypoints
};
}
}
},
(manifest, stats) => {
expect(manifest).toEqual({
entrypoints: {
one: ['one.js'],
two: ['two.js']
},
files: {
'one.js': 'one.js',
'two.js': 'two.js'
}
});

done();
});
});

describe('with CopyWebpackPlugin', function () {
it('works when including copied assets', function (done) {
webpackCompile({
Expand Down