1
|
/*
|
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
Author Tobias Koppers @sokra
|
4
|
*/
|
5
|
"use strict";
|
6
|
const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
7
|
|
8
|
/** @typedef {import("./Compiler")} Compiler */
|
9
|
|
10
|
class SingleEntryPlugin {
|
11
|
/**
|
12
|
* An entry plugin which will handle
|
13
|
* creation of the SingleEntryDependency
|
14
|
*
|
15
|
* @param {string} context context path
|
16
|
* @param {string} entry entry path
|
17
|
* @param {string} name entry key name
|
18
|
*/
|
19
|
constructor(context, entry, name) {
|
20
|
this.context = context;
|
21
|
this.entry = entry;
|
22
|
this.name = name;
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* @param {Compiler} compiler the compiler instance
|
27
|
* @returns {void}
|
28
|
*/
|
29
|
apply(compiler) {
|
30
|
compiler.hooks.compilation.tap(
|
31
|
"SingleEntryPlugin",
|
32
|
(compilation, { normalModuleFactory }) => {
|
33
|
compilation.dependencyFactories.set(
|
34
|
SingleEntryDependency,
|
35
|
normalModuleFactory
|
36
|
);
|
37
|
}
|
38
|
);
|
39
|
|
40
|
compiler.hooks.make.tapAsync(
|
41
|
"SingleEntryPlugin",
|
42
|
(compilation, callback) => {
|
43
|
const { entry, name, context } = this;
|
44
|
|
45
|
const dep = SingleEntryPlugin.createDependency(entry, name);
|
46
|
compilation.addEntry(context, dep, name, callback);
|
47
|
}
|
48
|
);
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* @param {string} entry entry request
|
53
|
* @param {string} name entry name
|
54
|
* @returns {SingleEntryDependency} the dependency
|
55
|
*/
|
56
|
static createDependency(entry, name) {
|
57
|
const dep = new SingleEntryDependency(entry);
|
58
|
dep.loc = { name };
|
59
|
return dep;
|
60
|
}
|
61
|
}
|
62
|
|
63
|
module.exports = SingleEntryPlugin;
|