Projekt

Obecné

Profil

Stáhnout (1.39 KB) Statistiky
| Větev: | Revize:
1
/*
2
	MIT License http://www.opensource.org/licenses/mit-license.php
3
	Author Tobias Koppers @sokra
4
	*/
5
"use strict";
6

    
7
const DllEntryPlugin = require("./DllEntryPlugin");
8
const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin");
9
const LibManifestPlugin = require("./LibManifestPlugin");
10

    
11
const validateOptions = require("schema-utils");
12
const schema = require("../schemas/plugins/DllPlugin.json");
13

    
14
/** @typedef {import("../declarations/plugins/DllPlugin").DllPluginOptions} DllPluginOptions */
15

    
16
class DllPlugin {
17
	/**
18
	 * @param {DllPluginOptions} options options object
19
	 */
20
	constructor(options) {
21
		validateOptions(schema, options, "Dll Plugin");
22
		this.options = options;
23
	}
24

    
25
	apply(compiler) {
26
		compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => {
27
			const itemToPlugin = (item, name) => {
28
				if (Array.isArray(item)) {
29
					return new DllEntryPlugin(context, item, name);
30
				}
31
				throw new Error("DllPlugin: supply an Array as entry");
32
			};
33
			if (typeof entry === "object" && !Array.isArray(entry)) {
34
				Object.keys(entry).forEach(name => {
35
					itemToPlugin(entry[name], name).apply(compiler);
36
				});
37
			} else {
38
				itemToPlugin(entry, "main").apply(compiler);
39
			}
40
			return true;
41
		});
42
		new LibManifestPlugin(this.options).apply(compiler);
43
		if (!this.options.entryOnly) {
44
			new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler);
45
		}
46
	}
47
}
48

    
49
module.exports = DllPlugin;
(35-35/144)