|
1 | 1 | /* |
2 | 2 | MIT License http://www.opensource.org/licenses/mit-license.php |
3 | 3 | Author Tobias Koppers @sokra |
4 | | -*/ |
5 | | -var DllEntryPlugin = require("./DllEntryPlugin"); |
6 | | -var LibManifestPlugin = require("./LibManifestPlugin"); |
7 | | -var FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin"); |
| 4 | + */ |
| 5 | +"use strict"; |
8 | 6 |
|
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 | + } |
11 | 36 | } |
| 37 | + |
12 | 38 | 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