1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | Author Tobias Koppers @sokra
|
---|
4 | */
|
---|
5 |
|
---|
6 | "use strict";
|
---|
7 |
|
---|
8 | const RequireIncludeDependency = require("./RequireIncludeDependency");
|
---|
9 | const RequireIncludeDependencyParserPlugin = require("./RequireIncludeDependencyParserPlugin");
|
---|
10 |
|
---|
11 | class RequireIncludePlugin {
|
---|
12 | apply(compiler) {
|
---|
13 | compiler.hooks.compilation.tap(
|
---|
14 | "RequireIncludePlugin",
|
---|
15 | (compilation, { normalModuleFactory }) => {
|
---|
16 | compilation.dependencyFactories.set(
|
---|
17 | RequireIncludeDependency,
|
---|
18 | normalModuleFactory
|
---|
19 | );
|
---|
20 | compilation.dependencyTemplates.set(
|
---|
21 | RequireIncludeDependency,
|
---|
22 | new RequireIncludeDependency.Template()
|
---|
23 | );
|
---|
24 |
|
---|
25 | const handler = (parser, parserOptions) => {
|
---|
26 | if (parserOptions.requireInclude === false) return;
|
---|
27 | const warn = parserOptions.requireInclude === undefined;
|
---|
28 |
|
---|
29 | new RequireIncludeDependencyParserPlugin(warn).apply(parser);
|
---|
30 | };
|
---|
31 |
|
---|
32 | normalModuleFactory.hooks.parser
|
---|
33 | .for("javascript/auto")
|
---|
34 | .tap("RequireIncludePlugin", handler);
|
---|
35 | normalModuleFactory.hooks.parser
|
---|
36 | .for("javascript/dynamic")
|
---|
37 | .tap("RequireIncludePlugin", handler);
|
---|
38 | }
|
---|
39 | );
|
---|
40 | }
|
---|
41 | }
|
---|
42 | module.exports = RequireIncludePlugin;
|
---|