Skip to content

Commit 9cf5901

Browse files
ahmedelgabriTheLarkInn
authored andcommitted
refactor(ES6): upgrade DllPlugin to ES6 (webpack#3760)
1 parent 9f6a601 commit 9cf5901

1 file changed

Lines changed: 32 additions & 26 deletions

File tree

lib/DllPlugin.js

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
/*
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
4-
*/
5-
var DllEntryPlugin = require("./DllEntryPlugin");
6-
var LibManifestPlugin = require("./LibManifestPlugin");
7-
var FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin");
4+
*/
5+
"use strict";
86

9-
function DllPlugin(options) {
10-
this.options = options;
7+
const DllEntryPlugin = require("./DllEntryPlugin");
8+
const LibManifestPlugin = require("./LibManifestPlugin");
9+
const FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin");
10+
11+
class DllPlugin {
12+
constructor(options) {
13+
this.options = options;
14+
}
15+
16+
apply(compiler) {
17+
compiler.plugin("entry-option", (context, entry) => {
18+
function itemToPlugin(item, name) {
19+
if(Array.isArray(item))
20+
return new DllEntryPlugin(context, item, name);
21+
else
22+
throw new Error("DllPlugin: supply an Array as entry");
23+
}
24+
if(typeof entry === "object" && !Array.isArray(entry)) {
25+
Object.keys(entry).forEach(name => {
26+
compiler.apply(itemToPlugin(entry[name], name));
27+
});
28+
} else {
29+
compiler.apply(itemToPlugin(entry, "main"));
30+
}
31+
return true;
32+
});
33+
compiler.apply(new LibManifestPlugin(this.options));
34+
compiler.apply(new FlagInitialModulesAsUsedPlugin());
35+
}
1136
}
37+
1238
module.exports = DllPlugin;
13-
DllPlugin.prototype.apply = function(compiler) {
14-
compiler.plugin("entry-option", function(context, entry) {
15-
function itemToPlugin(item, name) {
16-
if(Array.isArray(item))
17-
return new DllEntryPlugin(context, item, name);
18-
else
19-
throw new Error("DllPlugin: supply an Array as entry");
20-
}
21-
if(typeof entry === "object" && !Array.isArray(entry)) {
22-
Object.keys(entry).forEach(function(name) {
23-
compiler.apply(itemToPlugin(entry[name], name));
24-
});
25-
} else {
26-
compiler.apply(itemToPlugin(entry, "main"));
27-
}
28-
return true;
29-
});
30-
compiler.apply(new LibManifestPlugin(this.options));
31-
compiler.apply(new FlagInitialModulesAsUsedPlugin());
32-
};

0 commit comments

Comments
 (0)