source: imaps-frontend/node_modules/webpack/lib/dependencies/RequireEnsurePlugin.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const RequireEnsureDependency = require("./RequireEnsureDependency");
9const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
10
11const RequireEnsureDependenciesBlockParserPlugin = require("./RequireEnsureDependenciesBlockParserPlugin");
12
13const {
14 JAVASCRIPT_MODULE_TYPE_AUTO,
15 JAVASCRIPT_MODULE_TYPE_DYNAMIC
16} = require("../ModuleTypeConstants");
17const {
18 evaluateToString,
19 toConstantDependency
20} = require("../javascript/JavascriptParserHelpers");
21
22/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
23/** @typedef {import("../Compiler")} Compiler */
24/** @typedef {import("../javascript/JavascriptParser")} Parser */
25
26const PLUGIN_NAME = "RequireEnsurePlugin";
27
28class RequireEnsurePlugin {
29 /**
30 * Apply the plugin
31 * @param {Compiler} compiler the compiler instance
32 * @returns {void}
33 */
34 apply(compiler) {
35 compiler.hooks.compilation.tap(
36 PLUGIN_NAME,
37 (compilation, { normalModuleFactory }) => {
38 compilation.dependencyFactories.set(
39 RequireEnsureItemDependency,
40 normalModuleFactory
41 );
42 compilation.dependencyTemplates.set(
43 RequireEnsureItemDependency,
44 new RequireEnsureItemDependency.Template()
45 );
46
47 compilation.dependencyTemplates.set(
48 RequireEnsureDependency,
49 new RequireEnsureDependency.Template()
50 );
51
52 /**
53 * @param {Parser} parser parser parser
54 * @param {JavascriptParserOptions} parserOptions parserOptions
55 * @returns {void}
56 */
57 const handler = (parser, parserOptions) => {
58 if (
59 parserOptions.requireEnsure !== undefined &&
60 !parserOptions.requireEnsure
61 )
62 return;
63
64 new RequireEnsureDependenciesBlockParserPlugin().apply(parser);
65 parser.hooks.evaluateTypeof
66 .for("require.ensure")
67 .tap(PLUGIN_NAME, evaluateToString("function"));
68 parser.hooks.typeof
69 .for("require.ensure")
70 .tap(
71 PLUGIN_NAME,
72 toConstantDependency(parser, JSON.stringify("function"))
73 );
74 };
75
76 normalModuleFactory.hooks.parser
77 .for(JAVASCRIPT_MODULE_TYPE_AUTO)
78 .tap(PLUGIN_NAME, handler);
79 normalModuleFactory.hooks.parser
80 .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
81 .tap(PLUGIN_NAME, handler);
82 }
83 );
84 }
85}
86module.exports = RequireEnsurePlugin;
Note: See TracBrowser for help on using the repository browser.